使用MySQL 5.5、STS 2.9.2、MySQL-connector-java-5.1.21-bin.jar
我想从ResultSet中获取一个数组。
所以我这样编码:
try {
Connection conn = DriverManager.getConnection(url, id, pass);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
if (rs.next()) {
Array code = rs.getArray("code");
Array count = rs.getArray("count");
Object objCode = code.getArray();
Object objCount = count.getArray();
int[] itemCode = (int[]) objCode;
int[] itemCount = (int[]) objCount;
// do something
}
conn.close();
stmt.close();
rs.close();
} catch(SQLException e) {
printError(e);
}
然后,我得到一个
SQLFeatureNotSupportedException
在getArray()
。如果我删除这一行,它不会给出这个例外。
我搜索了一下,发现这是因为JDBC驱动程序不支持这种方法。我不明白它说什么,我该如何解决这个问题?
最佳答案
.getArray方法获取数组SQL数据类型。例如:.getDecimal获取十进制SQL数据类型等。。。MySQL(例如)不支持数组数据类型。因此,Java报告:不支持特性。
如果要将所有字段作为索引数组获取,请对索引1处的VARCHAR列值使用.getString(1)。
示例查询:SELECT id,title FROM news其中id=1;
所以可以用.getInt(1)获取id,用.getString(2)获取title。
我只能这么说)
关于java - getArray上的SQLFeatureNotSupportedException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11735786/