tursodatabase/turso · error · java.sql.SQLException
Exception while binding long value at position {position}
Error message
Exception while binding long value at position {position} What it means
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().
Source
Thrown at bindings/java/src/main/java/tech/turso/core/TursoStatement.java:154
* @return A result code indicating the success or failure of the operation.
* @throws SQLException If a database access error occurs.
*/
public int bindInt(int position, int value) throws SQLException {
return bindLong(position, value);
}
/**
* Binds a long 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 bindLong(int position, long value) throws SQLException {
final int result = bindLong(statementPointer, position, value);
if (result != 0) {
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);View on GitHub (pinned to 244cde92a7)
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
Example fix
// before
for (int i = 0; i < ids.length; i++) {
stmt.bindLong(i, ids[i]); // first call uses position 0 -> throws
}
// after
for (int i = 0; i < ids.length; i++) {
stmt.bindLong(i + 1, ids[i]); // positions are 1-based
} Defensive patterns
Strategy: validation
Validate before calling
int paramCount = stmt.parameterCount();
if (position < 1 || position > paramCount) {
throw new IllegalArgumentException("bind position must be 1.." + paramCount);
}
stmt.bindLong(position, value); // also the funnel for bindInt and Integer/Byte/Short via bindObject Try / catch
try {
stmt.bindLong(position, value);
} catch (SQLException e) {
throw new IllegalArgumentException(
"bind failed for position " + position + " (1-based, max " + safeParamCount(stmt) + ")", e);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Exception while binding NULL value at position {position}
- Exception while binding double value at position {position}
- Exception while binding text value at position {position}
- Exception while binding blob value at position {position}
- Unsupported object type in bindObject: {className}
AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20).
Data as JSON: /api/errors/f886d19d5b278458.
Report an issue: GitHub.