tursodatabase/turso · error · SQLException

ResultSet is null

Error message

ResultSet is null

What it means

get(int) requires a current row: lastStepResult must be non-null and hold a row payload. It is null when next() never ran (note TursoStatement.execute() steps once internally), and getResult() is null when the cursor is past the last row or the result is empty. In short: reading a column with no row under the cursor.

Source

Thrown at bindings/java/src/main/java/tech/turso/core/TursoResultSet.java:165

  public Object get(String columnName) throws SQLException {
    final int columnsLength = this.columnNames.length;
    for (int i = 0; i < columnsLength; i++) {
      if (this.columnNames[i].equals(columnName)) {
        return get(i + 1);
      }
    }

    throw new SQLException("column name " + columnName + " not found");
  }

  public Object get(int columnIndex) throws SQLException {
    if (!this.isOpen()) {
      throw new SQLException("ResultSet is not open");
    }

    if (this.lastStepResult == null || this.lastStepResult.getResult() == null) {
      throw new SQLException("ResultSet is null");
    }

    final Object[] resultSet = this.lastStepResult.getResult();
    if (columnIndex > resultSet.length || columnIndex < 0) {
      throw new SQLException("columnIndex out of bound");
    }

    return resultSet[columnIndex - 1];
  }

  public String[] getColumnNames() {
    return this.columnNames;
  }

  public void setColumnNames(String[] columnNames) {
    this.columnNames = columnNames;
  }

View on GitHub (pinned to bad083fafb)

Solutions

  1. Always guard reads with the iteration: if (rs.next()) { Object v = rs.get(1); }
  2. Use hasLastStepReturnedRow() to confirm a row is present before optional reads
  3. Treat next() == false as 'no data' and skip value extraction entirely

Example fix

// before
rs.get(1); // no next() called yet -> ResultSet is null

// after
if (rs.next()) {
  Object v = rs.get(1);
}
Defensive patterns

Strategy: validation

Validate before calling

if (rs.next()) {          // cursor now sits on a real row
  Object v = rs.get(1);
}

Prevention

When it happens

Trigger: Calling rs.get(1) before any rs.next(); reading after next() returned false; reading after execute() reported no rows; reading an empty result set.

Common situations: Missing if (rs.next()) guard around reads; code assuming execute() leaves the cursor on row 1; re-reading values after the iteration loop completed; SELECT COUNT-style queries where the developer assumed a row exists unconditionally.

Related errors


AI-assisted analysis of tursodatabase/turso@bad083fafb (2026-08-16). Data as JSON: /api/errors/e57a8c21211be3e5. Report an issue: GitHub.