{"record":{"id":"02be165242c276eb","repo":"tursodatabase/turso","slug":"exception-while-binding-blob-value-at-position-po","errorCode":null,"errorMessage":"Exception while binding blob value at position {position}","messagePattern":"Exception while binding blob 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":210,"sourceCode":"    }\n    return result;\n  }\n\n  private native int bindText(long statementPointer, int position, String value)\n      throws SQLException;\n\n  /**\n   * Binds a blob 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 bindBlob(int position, byte[] value) throws SQLException {\n    final int result = bindBlob(statementPointer, position, value);\n    if (result != 0) {\n      throw new SQLException(\"Exception while binding blob value at position \" + position);\n    }\n    return result;\n  }\n\n  private native int bindBlob(long statementPointer, int position, byte[] value)\n      throws SQLException;\n\n  public void bindObject(int parameterIndex, Object x) throws SQLException {\n    if (x == null) {\n      this.bindNull(parameterIndex);\n      return;\n    }\n    if (x instanceof Byte) {\n      this.bindInt(parameterIndex, (Byte) x);\n    } else if (x instanceof Short) {\n      this.bindInt(parameterIndex, (Short) x);\n    } else if (x instanceof Integer) {\n      this.bindInt(parameterIndex, (Integer) x);","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/java/src/main/java/tech/turso/core/TursoStatement.java#L192-L228","documentation":"bindBlob(position, value) throws when the native bind returns a non-zero result code; the dominant cause is an out-of-range parameter position (SQLITE_RANGE). As with text, a null byte[] should be bound with bindNull rather than passed here. Positions are 1-based and bounded by parameterCount().","triggerScenarios":"bindBlob(0, bytes) or a position above the placeholder count; binding a null array instead of using bindNull; binding on a finalized statement.","commonSituations":"0-based positions from ported code; optional binary fields forwarded without a null check; SQL edits changing the placeholder count.","solutions":["Use 1-based positions validated against stmt.parameterCount()","Use bindNull for absent blobs instead of passing null arrays","Keep SQL text and the blob bind calls together"],"exampleFix":"// before\nstmt.bindBlob(0, data); // throws\n\n// after\nif (data == null) {\n  stmt.bindNull(1);\n} else {\n  stmt.bindBlob(1, data); // 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}\nif (value == null) {\n  stmt.bindNull(position); // null blobs must not go through bindBlob\n} else {\n  stmt.bindBlob(position, value);\n}","typeGuard":null,"tryCatchPattern":"try {\n  stmt.bindBlob(position, value);\n} catch (SQLException e) {\n  throw new IllegalArgumentException(\n      \"bind failed for position \" + position + \" (1-based, max \" + safeParamCount(stmt) + \")\", e);\n}","preventionTips":["Route null byte[] values through bindNull","Validate positions with parameterCount() in a shared helper","Keep SQL text and blob binds adjacent"],"tags":["java","jdbc","prepared-statement","bind","parameter-index","blob"],"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"}