tursodatabase/turso · error · SQLException

SQLite only supports closing cursors at commit

Error message

SQLite only supports closing cursors at commit

What it means

checkCursor() rejects holdability other than CLOSE_CURSORS_AT_COMMIT: cursors do not survive transaction boundaries in this engine, so requesting HOLD_CURSORS_OVER_COMMIT fails up front. Any result set must be fully consumed or closed before the enclosing transaction commits.

Solutions

  1. Pass ResultSet.CLOSE_CURSORS_AT_COMMIT or use the overloads without a holdability argument
  2. Consume/close result sets before calling commit() — which the engine requires anyway
  3. Configure the pool/app-server wrapper to preserve default holdability

Example fix

// before
Statement st = conn.createStatement(
    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);

// after
Statement st = conn.createStatement(
    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
Defensive patterns

Strategy: validation

Validate before calling

int holdability = resultSetHoldability == ResultSet.CLOSE_CURSORS_AT_COMMIT
    ? resultSetHoldability : ResultSet.CLOSE_CURSORS_AT_COMMIT;
Statement st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, holdability);

Try / catch

try {
  return conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, requested);
} catch (SQLException e) {
  if (e.getMessage().contains("closing cursors at commit")) {
    return conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling createStatement/prepareStatement with ResultSet.HOLD_CURSORS_OVER_COMMIT as the third parameter; container-managed code (some app servers, pooled wrappers) requesting hold-over-commit by default.

Common situations: App servers or connection pools rewriting statement creation with their own holdability; code ported from databases where cursors persist past commit; generated JDBC code with all three constants spelled out.

Related errors


AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20). Data as JSON: /api/errors/12093592de906e40. Report an issue: GitHub.

Appendix: source

Thrown at bindings/java/src/main/java/tech/turso/core/TursoConnection.java:166

   *   <li>type: {@link ResultSet#TYPE_FORWARD_ONLY}
   *   <li>concurrency: {@link ResultSet#CONCUR_READ_ONLY})
   *   <li>holdability: {@link ResultSet#CLOSE_CURSORS_AT_COMMIT}
   * </ul>
   *
   * @param resultSetType the type setting.
   * @param resultSetConcurrency the concurrency setting.
   * @param resultSetHoldability the holdability setting.
   */
  public void checkCursor(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
      throws SQLException {
    if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
      throw new SQLException("SQLite only supports TYPE_FORWARD_ONLY cursors");
    }
    if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
      throw new SQLException("SQLite only supports CONCUR_READ_ONLY cursors");
    }
    if (resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
      throw new SQLException("SQLite only supports closing cursors at commit");
    }
  }

  /**
   * Sets the auto-commit mode for this connection.
   *
   * <p>When auto-commit is enabled (the default), each SQL statement is committed automatically
   * upon completion. When auto-commit is disabled, statements are grouped into transactions that
   * must be explicitly committed or rolled back.
   *
   * <p>If this method is called to enable auto-commit while a transaction is active, the current
   * transaction is committed first.
   *
   * @param autoCommit true to enable auto-commit mode; false to disable it
   * @throws SQLException if a database access error occurs or the connection is closed
   */
  public void setAutoCommit(boolean autoCommit) throws SQLException {
    synchronized (transactionLock) {

View on GitHub (pinned to 244cde92a7)