我正在查询information_schema.columns
我的 PostgreSQL 数据库中的表。使用表名,结果集查找所有列名、类型以及是否可为空(主键“id”除外)。这是正在使用的查询:
SELECT column_name, is_nullable,data_type FROM information_schema.columns
WHERE lower(table_name) = lower('TABLE1') AND column_name != 'id'
ORDER BY ordinal_position;
我对每个结果都有一个字符串数组,并且我正在尝试使用 ResultSet 方法getArray(String columnLabel) https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html#getArray-java.lang.String-以避免循环遍历结果。我想将返回的数组存储在字符串数组中,但出现类型不匹配错误
Type mismatch: cannot convert from Array to String[]
有没有办法将 SQL 数组对象转换或类型转换为 String[]?
相关代码:
String[] columnName, type, nullable;
//Get Field Names, Type, & Nullability
String query = "SELECT column_name, is_nullable,data_type FROM information_schema.columns "
+ "WHERE lower(table_name) = lower('"+tableName+"') AND column_name != 'id' "
+ "ORDER BY ordinal_position";
try{
ResultSet rs = Query.executeQueryWithRS(c, query);
columnName = rs.getArray(rs.getArray("column_name"));
type = rs.getArray("data_type");
nullable = rs.getArray("is_nullable");
}catch (Exception e) {
e.printStackTrace();
}