{"record":{"id":"f886d19d5b278458","repo":"tursodatabase/turso","slug":"exception-while-binding-long-value-at-position-po","errorCode":null,"errorMessage":"Exception while binding long value at position {position}","messagePattern":"Exception while binding long value at position (.+?)","errorType":"exception","errorClass":"java.sql.SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/core/TursoStatement.java","lineNumber":154,"sourceCode":"   * @return A result code indicating the success or failure of the operation.\n   * @throws SQLException If a database access error occurs.\n   */\n  public int bindInt(int position, int value) throws SQLException {\n    return bindLong(position, value);\n  }\n\n  /**\n   * Binds a long 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 bindLong(int position, long value) throws SQLException {\n    final int result = bindLong(statementPointer, position, value);\n    if (result != 0) {\n      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);","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/java/src/main/java/tech/turso/core/TursoStatement.java#L136-L172","documentation":"bindLong(position, value) throws when the native bind returns a non-zero result code; the dominant cause is SQLITE_RANGE from an out-of-range position. This is also the funnel for all integer binding: bindInt delegates to bindLong because the engine treats every integer as a 64-bit long, and bindObject routes Integer, Byte, and Short here as well. Positions are 1-based and bounded by parameterCount().","triggerScenarios":"bindLong(0, v) from 0-based caller code; position greater than the number of placeholders in the SQL; binding integers on a finalized or closed statement.","commonSituations":"Converting a 0-based index from an array or JSON into a bind position; SQL string gaining or losing placeholders after an edit while bind code lags.","solutions":["Use 1-based positions: the i-th '?' is bound with i","Validate position against stmt.parameterCount() before binding","Keep SQL text and the integer bind sequence in one place"],"exampleFix":"// before\nfor (int i = 0; i < ids.length; i++) {\n  stmt.bindLong(i, ids[i]); // first call uses position 0 -> throws\n}\n\n// after\nfor (int i = 0; i < ids.length; i++) {\n  stmt.bindLong(i + 1, ids[i]); // positions are 1-based\n}","handlingStrategy":"validation","validationCode":"int paramCount = stmt.parameterCount();\nif (position < 1 || position > paramCount) {\n  throw new IllegalArgumentException(\"bind position must be 1..\" + paramCount);\n}\nstmt.bindLong(position, value); // also the funnel for bindInt and Integer/Byte/Short via bindObject","typeGuard":null,"tryCatchPattern":"try {\n  stmt.bindLong(position, value);\n} catch (SQLException e) {\n  throw new IllegalArgumentException(\n      \"bind failed for position \" + position + \" (1-based, max \" + safeParamCount(stmt) + \")\", e);\n}","preventionTips":["Convert 0-based caller indexes with +1 at the boundary, in one place","Re-check parameterCount() whenever the SQL text changes","Keep integer binds adjacent to the SQL they populate"],"tags":["java","jdbc","prepared-statement","bind","parameter-index"],"backgroundTag":"parameter-bind-failed","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}