On the server, trying to get data from the table.

result = DBexecutor.executeQuery("SELECT * FROM mappacks WHERE ROWID >="+startWith+" AND ROWID <="+endWith+";" ); while (result.next()){ MapPackStructure mapPack = gson.fromJson((result.getString("JSON")), MapPackStructure.class); TreeMap pack = new TreeMap(){{ put("ID", mapPack.getID()); put("name", mapPack.getName()); put("author", mapPack.getAuthor()); put("preview", "/static/mappack/"+mapPack.getID()+"/png"); }}; ArrayList<TreeMap> levels = new ArrayList<>(); for(Integer levelID: mapPack.getMaps()) { ResultSet innerResult; innerResult = DBexecutor.executeQuery("SELECT * FROM levels WHERE ID =" + levelID + ";"); while (innerResult.next()) { levels.add(new TreeMap() {{ put("ID", innerResult.getString("ID")); put("name", innerResult.getString("name")); put("author", innerResult.getString("Author")); }}); } } pack.put("levels", levels); rendered += config.renderTemplate(template, pack); System.out.println(rendered); DBexecutor.close(); } //startWith = 1 endWith = 5 

In total, there are 3 rows in the table, I get only one entry to the output, while the internal query works fine.

What is interesting, even if the query is "SELECT * FROM mappacks", I get only one entry

  • 2
    And what does the DBexecutor.close() method DBexecutor.close() ? Does he accidentally close all resources, including result (or the connection within which the result was obtained)? - Roman
  • Roman is right. ResultSet lives with an active connection and stores data only about the current line. You close the connection and as a result cannot request the next line. - Riĥard Brugekĥaim
  • No, it did not help - nk2

1 answer 1

Everything turned out to be simple. SQLite does not allow you to make a query with an unclosed query (query in the query) in one database. The only solution is to switch to cassandra and the like.