{"record":{"id":"90ce55f8fcdb9b0a","repo":"tursodatabase/turso","slug":"the-resultset-is-not-open","errorCode":null,"errorMessage":"The resultSet is not open","messagePattern":"The resultSet is not open","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/core/TursoResultSet.java","lineNumber":74,"sourceCode":"    while (next()) {}\n  }\n\n  /**\n   * Moves the cursor forward one row from its current position. A {@link TursoResultSet} cursor is\n   * initially positioned before the first fow; the first call to the method <code>next</code> makes\n   * the first row the current row; the second call makes the second row the current row, and so on.\n   * When a call to the <code>next</code> method returns <code>false</code>, the cursor is\n   * positioned after the last row.\n   *\n   * <p>Note that turso only supports <code>ResultSet.TYPE_FORWARD_ONLY</code>, which means that the\n   * cursor can only move forward.\n   *\n   * @return true if the new current row is valid; false if there are no more rows\n   * @throws SQLException if a database access error occurs\n   */\n  public boolean next() throws SQLException {\n    if (!open) {\n      throw new SQLException(\"The resultSet is not open\");\n    }\n\n    if (isEmptyResultSet || pastLastRow) {\n      return false; // completed ResultSet\n    }\n\n    if (maxRows != 0 && row == maxRows) {\n      return false;\n    }\n\n    lastStepResult = this.statement.step();\n    log.debug(\"lastStepResult: {}\", lastStepResult);\n    if (lastStepResult.isRow()) {\n      row++;\n    }\n\n    if (lastStepResult.isInInvalidState()) {\n      open = false;","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/bindings/java/src/main/java/tech/turso/core/TursoResultSet.java#L56-L92","documentation":"TursoResultSet.next() throws when open is false. A set starts open (constructed via TursoResultSet.of), and becomes closed by close(), by statement.close() (which closes its shared ResultSet), by reset(), or by next() itself when a step returned an invalid state (it sets open = false before throwing).","triggerScenarios":"Calling next() after rs.close() or stmt.close(); calling next() again after a previous next() threw an invalid-state SQLException; iterating the old ResultSet after TursoStatement.reset().","commonSituations":"finally-block loops that keep calling next() after the body threw; try-with-resources scoping where the statement closes before a later iteration; double consumption of the same statement result by helper methods.","solutions":["Iterate exactly once with while (rs.next()) { ... } and never call next() after an exception","Check rs.isOpen() before any optional extra next() call","After a step error, re-prepare/re-execute instead of continuing to step the dead set"],"exampleFix":"// before\ntry { while (rs.next()) { process(rs); } }\ncatch (SQLException e) { /* ... */ }\nfinally { while (rs.next()) {} } // throws: The resultSet is not open\n\n// after\ntry {\n  while (rs.isOpen() && rs.next()) { process(rs); }\n} catch (SQLException e) {\n  // rs is closed now — do not step it again\n}","handlingStrategy":"try-catch","validationCode":"while (rs.isOpen() && rs.next()) {\n  process(rs);\n}","typeGuard":null,"tryCatchPattern":"try {\n  while (rs.next()) {\n    process(rs);\n  }\n} catch (SQLException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"resultSet is not open\")) {\n    // set was closed underneath — stop iterating, do not call next() again\n  } else {\n    throw e;\n  }\n}","preventionTips":["Iterate each ResultSet exactly once, inside the statement's lifetime","Never call next() in finally blocks after the body may have thrown","Scope try-with-resources so the ResultSet is fully consumed before the statement closes"],"tags":["java","jdbc","resultset","iteration","bindings"],"backgroundTag":"resultset-already-closed","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}