数据库元数据获取列详细信息
我使用数据库元数据来查找列大小。但 getColumns(null,null,"table_name",null) 返回一个空结果集。我通过查询来检查该表,并且该表存在。错误在哪里?提前致谢!
更新:
Connection connection = getConnection(); //getting the connection -
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("select * from table_name");
while (rs.next()) {
System.out.println(rs.getString("column_name")); //The values get printed
}
ResultSet rsColumns = null;
DatabaseMetaData meta = connection.getMetaData();
rsColumns = meta.getColumns(null, null, "table_name",null);
System.out.println(rsColumns.next()); // I get false here which means resultset is empty. But I dunno why.
I use databasemetadata to find the column size. But getColumns(null,null,"table_name",null) returns an empty resultset. I checked for the table by querying it and the table is present. Where is the error? Thanks in advance!
Update:
Connection connection = getConnection(); //getting the connection -
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("select * from table_name");
while (rs.next()) {
System.out.println(rs.getString("column_name")); //The values get printed
}
ResultSet rsColumns = null;
DatabaseMetaData meta = connection.getMetaData();
rsColumns = meta.getColumns(null, null, "table_name",null);
System.out.println(rsColumns.next()); // I get false here which means resultset is empty. But I dunno why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用哪个数据库?这可能与它如何处理不带引号的标识符有关,遵循标准的数据库会自动将它们存储为大写。您可以通过调用
storesUpperCaseIdentifiers
方法以编程方式检查它是否执行此操作。解决方案是在创建表时使用带引号的标识符,或者如果
storesUpperCaseIdentifiers
返回 true,则对表名称字符串调用toUpperCase
方法。Which database are you using? It's probably related to how it handle unquoted identifiers, databases that follow the standard automatically store them in upper case. You can programmatically check if it does that by calling the
storesUpperCaseIdentifiers
method.The solution would be to either use quoted identifiers while creating the table or calling the
toUpperCase
method on the table name string ifstoresUpperCaseIdentifiers
returns true.您可以尝试以下代码片段吗:
我认为您缺少“COLUMN_SIZE”。
Can you try the below snippet:
I think you are missing the "COLUMN_SIZE".