我正在尝试使用ResultSet并将其内容添加到字符串数组中。
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery(String.format("SELECT * FROM %s", TABLE_STUDENTS));
Array resultArrayStudent = resultSetStudent.getArray(1);
String[] studentIds = (String[])resultArrayStudent.getArray();
但是我收到以下错误:
java.sql.SQLException: not implemented by SQLite JDBC driver
at org.sqlite.jdbc4.JDBC4ResultSet.unused(JDBC4ResultSet.java:333)
at org.sqlite.jdbc4.JDBC4ResultSet.getArray(JDBC4ResultSet.java:340)
at models.DataSource.classesTakenByEachStudent(DataSource.java:400)
at Main.main(Main.java:81)
可能导致抛出此异常的原因是什么?我使用的是sqlite jdbc 3.18.0。
答案 0 :(得分:0)
不,你不能直接得到一个数组,你必须循环抛出你的resultSet并获得标识,你可以使用:
ResultSet resultSet = statement.executeQuery(String.format("....", TABLE_STUDENTS));
List<String> list = new ArrayList<>();//create a List
while (resultSet.next()){//loop throw the result set
list.add(resultSetStudent.getString("id"));//use the name of your col you want to get
}