{"record":{"id":"186ccb00c0786d69","repo":"tursodatabase/turso","slug":"exception-while-binding-double-value-at-position","errorCode":null,"errorMessage":"Exception while binding double value at position \" + position","messagePattern":"Exception while binding double value at position \" \\+ position","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/core/TursoStatement.java","lineNumber":172,"sourceCode":"      throw new SQLException(\"Exception while binding long value at position \" + position);\n    }\n    return result;\n  }\n\n  private native int bindLong(long statementPointer, int position, long value) throws SQLException;\n\n  /**\n   * Binds a double value to the prepared statement at the specified position.\n   *\n   * @param position The index of the SQL parameter to be set.\n   * @param value The value to bind to the parameter.\n   * @return <a href=\"https://www.sqlite.org/c3ref/c_abort.html\">Result Codes</a>\n   * @throws SQLException If a database access error occurs.\n   */\n  public int bindDouble(int position, double value) throws SQLException {\n    final int result = bindDouble(statementPointer, position, value);\n    if (result != 0) {\n      throw new SQLException(\"Exception while binding double value at position \" + position);\n    }\n    return result;\n  }\n\n  private native int bindDouble(long statementPointer, int position, double value)\n      throws SQLException;\n\n  /**\n   * Binds a text value to the prepared statement at the specified position.\n   *\n   * @param position The index of the SQL parameter to be set.\n   * @param value The value to bind to the parameter.\n   * @return <a href=\"https://www.sqlite.org/c3ref/c_abort.html\">Result Codes</a>\n   * @throws SQLException If a database access error occurs.\n   */\n  public int bindText(int position, String value) throws SQLException {\n    final int result = bindText(statementPointer, position, value);\n    if (result != 0) {","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/bindings/java/src/main/java/tech/turso/core/TursoStatement.java#L154-L190","documentation":"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.","triggerScenarios":"stmt.bindDouble(position, value) with position > parameterCount(); 0-based positions; binding on a closed/finalized statement; binding after the owning connection was closed.","commonSituations":"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.","solutions":["Use 1-based positions (first parameter is 1, not 0).","Validate position against stmt.parameterCount() before binding and treat a mismatch as a programming error.","Ensure the statement and connection are still open at bind time.","Log the SQL text alongside the failing position so placeholder-count mismatches are obvious."],"exampleFix":"// before\nstmt.bindDouble(0, 1.5); // 0-based: invalid position\n\n// after\nif (position < 1 || position > stmt.parameterCount()) {\n    throw new IllegalArgumentException(\"bind position out of range: \" + position);\n}\nstmt.bindDouble(position, 1.5);","handlingStrategy":"validation","validationCode":"if (!stmt.isClosed() && position >= 1 && position <= stmt.parameterCount()) {\n    stmt.bindDouble(position, value);\n} else {\n    throw new IllegalArgumentException(\"invalid bind: position=\" + position\n        + \", paramCount=\" + safeParamCount(stmt));\n}","typeGuard":null,"tryCatchPattern":"try {\n    stmt.bindDouble(position, value);\n} catch (SQLException e) {\n    throw new IllegalStateException(\"bindDouble failed at \" + position, e);\n}","preventionTips":["Use 1-based positions for every bind call.","Cache parameterCount() after prepare and validate against it in one shared helper.","Centralize all binds in a single bindParameters(stmt, Object[] args) utility that checks ranges once.","Close statements only after all binds and execution complete."],"tags":["java","jdbc","binding","double","jni","parameter-position"],"backgroundTag":"jdbc-parameter-binding","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}