tursodatabase/turso · error · SQLException

Invalid argument

Error message

Invalid argument

What it means

JDBC4Statement.getMoreResults(int) accepts only Statement.CLOSE_CURRENT_RESULT; any other flag (KEEP_CURRENT_RESULT, CLOSE_ALL_RESULTS) throws SQLException("Invalid argument"). Even the accepted path is single-result only: it closes the current result set, resets updateCount to -1, and always returns false — this driver does not expose multiple result sets per statement.

Solutions

  1. Call the no-arg getMoreResults(), which defaults to CLOSE_CURRENT_RESULT
  2. Restructure to one statement per result set; this driver never returns a second one
  3. Guard the flag: treat any value other than CLOSE_CURRENT_RESULT as an error before calling
  4. Catch the SQLException when reusing generic multi-result framework code that you cannot change

Example fix

// before
while (stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT)) { ... }

// after
// single result set per statement on this driver
try (ResultSet rs = stmt.getResultSet()) {
  while (rs.next()) { ... }
}
Defensive patterns

Strategy: validation

Validate before calling

if (current != Statement.CLOSE_CURRENT_RESULT) {
  // driver supports only CLOSE_CURRENT_RESULT; single result set per statement
  current = Statement.CLOSE_CURRENT_RESULT;
}
boolean more = stmt.getMoreResults(current);

Try / catch

try {
  return stmt.getMoreResults(current);
} catch (SQLException e) {
  if ("Invalid argument".equals(e.getMessage())) {
    return false; // driver has no additional result sets anyway
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT) or CLOSE_ALL_RESULTS, most often inside the standard JDBC multi-result iteration loop (while (stmt.getMoreResults(...)) after execute()), or inside generic DAO/stored-procedure helpers that preserve the current result set while probing for more.

Common situations: Porting multi-result-set iteration patterns written for MySQL/PostgreSQL/SQL Server drivers; engines or test harnesses that return several result sets per call; framework code that chooses a flag based on configuration.

Understand the failure class

Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.

Related errors


AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20). Data as JSON: /api/errors/f5c7d4251623f95c. Report an issue: GitHub.

Appendix: source

Thrown at bindings/java/src/main/java/tech/turso/jdbc4/JDBC4Statement.java:356

    return BATCH_COMPATIBLE_PATTERN.matcher(sql).find();
  }

  @Override
  public Connection getConnection() {
    return connection;
  }

  @Override
  public boolean getMoreResults() throws SQLException {
    return getMoreResults(Statement.CLOSE_CURRENT_RESULT);
  }

  @Override
  public boolean getMoreResults(int current) throws SQLException {
    requireNonNull(statement, "statement should not be null");

    if (current != Statement.CLOSE_CURRENT_RESULT) {
      throw new SQLException("Invalid argument");
    }

    statement.getResultSet().close();
    updateCount = -1;

    return false;
  }

  @Override
  @SkipNullableCheck
  public ResultSet getGeneratedKeys() throws SQLException {
    // TODO
    return null;
  }

  @Override
  public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
    // TODO: enhance

View on GitHub (pinned to 244cde92a7)