hwaal hwaal - 2 years ago 66
SQL Question

SQLite JDBS driver error: getarray not implemented

I am trying to take a ResultSet and add its contents to an array of Strings.

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();

However I am getting the following error:

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)

What could be causing this exception to be thrown? I am using sqlite jdbc 3.18.0.

Answer Source

No you can't get an Array directly, you have to loop throw your resultSet and get identifies, you can use :

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

Take a look ResultSet

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download