我正在查詢PostgreSQL數據庫中的information_schema.columns
表。使用表名稱,結果集會查找所有列名稱,類型以及是否爲空(除了主鍵'id')。這是正在使用的查詢:將結果集從SQL數組轉換爲字符串數組
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)
,以避免通過結果循環。我想返回數組存儲在字符串數組,卻得到了一個類型不匹配錯誤
Type mismatch: cannot convert from Array to String[]
有沒有辦法到SQL Array對象轉換或強制轉換爲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();
}
謝謝,我嘗試過使用'rs.getArray(「is_nullable」)。getArray()',但我認爲我沒有對它進行類型轉換。這似乎解決了我的問題。 – Matt 2013-02-18 11:36:49