tursodatabase/turso · error · SQLException

Exception while binding double value at position " + positio

Error message

Exception while binding double value at position " + position

What it means

Thrown when the JNI-native bindDouble call returns a non-zero SQLite result code. The native implementation returns SQLITE_ERROR when the statement pointer cannot be resolved to a live statement or when bind_at rejects the 1-based parameter position as out of range for this statement's SQL. The double value itself is never the problem; only the statement state or the position can fail.

Source

Thrown at bindings/java/src/main/java/tech/turso/core/TursoStatement.java:172

      throw new SQLException("Exception while binding long value at position " + position);
    }
    return result;
  }

  private native int bindLong(long statementPointer, int position, long value) throws SQLException;

  /**
   * Binds a double value to the prepared statement at the specified position.
   *
   * @param position The index of the SQL parameter to be set.
   * @param value The value to bind to the parameter.
   * @return <a href="https://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
   * @throws SQLException If a database access error occurs.
   */
  public int bindDouble(int position, double value) throws SQLException {
    final int result = bindDouble(statementPointer, position, value);
    if (result != 0) {
      throw new SQLException("Exception while binding double value at position " + position);
    }
    return result;
  }

  private native int bindDouble(long statementPointer, int position, double value)
      throws SQLException;

  /**
   * Binds a text value to the prepared statement at the specified position.
   *
   * @param position The index of the SQL parameter to be set.
   * @param value The value to bind to the parameter.
   * @return <a href="https://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
   * @throws SQLException If a database access error occurs.
   */
  public int bindText(int position, String value) throws SQLException {
    final int result = bindText(statementPointer, position, value);
    if (result != 0) {

View on GitHub (pinned to bad083fafb)

Solutions

  1. Use 1-based positions (first parameter is 1, not 0).
  2. Validate position against stmt.parameterCount() before binding and treat a mismatch as a programming error.
  3. Ensure the statement and connection are still open at bind time.
  4. Log the SQL text alongside the failing position so placeholder-count mismatches are obvious.

Example fix

// before
stmt.bindDouble(0, 1.5); // 0-based: invalid position

// after
if (position < 1 || position > stmt.parameterCount()) {
    throw new IllegalArgumentException("bind position out of range: " + position);
}
stmt.bindDouble(position, 1.5);
Defensive patterns

Strategy: validation

Validate before calling

if (!stmt.isClosed() && position >= 1 && position <= stmt.parameterCount()) {
    stmt.bindDouble(position, value);
} else {
    throw new IllegalArgumentException("invalid bind: position=" + position
        + ", paramCount=" + safeParamCount(stmt));
}

Try / catch

try {
    stmt.bindDouble(position, value);
} catch (SQLException e) {
    throw new IllegalStateException("bindDouble failed at " + position, e);
}

Prevention

When it happens

Trigger: stmt.bindDouble(position, value) with position > parameterCount(); 0-based positions; binding on a closed/finalized statement; binding after the owning connection was closed.

Common situations: Binding floating-point columns in generated loops with off-by-one indices; editing SQL to remove a placeholder while keeping the old bind sequence; pooled statements recycled before binding finishes.

Related errors


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