tursodatabase/turso · error · SQLException
Cannot commit in autocommit mode.
Error message
Cannot commit in autocommit mode.
What it means
TursoConnection.commit() refuses to run while autoCommit is true. In autocommit mode every statement commits itself on completion, so an explicit commit() has no meaning and — unlike some drivers that silently no-op — Turso throws to surface the transaction-management mistake.
Source
Thrown at bindings/java/src/main/java/tech/turso/core/TursoConnection.java:220
*
* @return true if auto-commit mode is enabled; false otherwise
* @throws SQLException if a database access error occurs or the connection is closed
*/
public boolean getAutoCommit() throws SQLException {
checkOpen();
return autoCommit;
}
/**
* Commits the current transaction.
*
* @throws SQLException if in auto-commit mode, closed, or database error occurs.
*/
public void commit() throws SQLException {
synchronized (transactionLock) {
checkOpen();
if (autoCommit) {
throw new SQLException("Cannot commit in autocommit mode.");
}
if (inTransaction) {
executeInternal("COMMIT");
inTransaction = false;
}
}
}
/**
* Rolls back the current transaction.
*
* @throws SQLException if in auto-commit mode, closed, or database error occurs.
*/
public void rollback() throws SQLException {
synchronized (transactionLock) {
checkOpen();
if (autoCommit) {View on GitHub (pinned to bad083fafb)
Solutions
- Call conn.setAutoCommit(false) before executing the statements you intend to commit
- Guard the call: if (!conn.getAutoCommit()) { conn.commit(); }
- Check pool configuration — verify the connection still has autocommit disabled when your code runs, and that a previous borrower did not re-enable it
Example fix
// before
conn.commit(); // throws: autoCommit is still true
// after
conn.setAutoCommit(false);
try (Statement st = conn.createStatement()) {
st.executeUpdate("UPDATE t SET a = 1");
conn.commit();
} Defensive patterns
Strategy: validation
Validate before calling
if (conn.getAutoCommit()) {
// autocommit mode: every statement already committed — nothing to do
} else {
conn.commit();
} Try / catch
try {
conn.commit();
} catch (SQLException e) {
if ("Cannot commit in autocommit mode.".equals(e.getMessage())) {
// benign: no transaction was open
} else {
throw e;
}
} Prevention
- Centralize transaction begin: one helper calls setAutoCommit(false), runs the work, commits, and restores autocommit
- Verify pool reset behavior (e.g. HikariCP autoCommit setting) so the connection state matches your commit calls
- Assert !conn.getAutoCommit() in tests before transactional code paths run
When it happens
Trigger: Calling conn.commit() without a prior conn.setAutoCommit(false), or after a pool/framework re-enabled autocommit on the connection. checkOpen() runs first, so the connection must also be open.
Common situations: Manual JDBC code that forgot setAutoCommit(false); finally { conn.commit(); } boilerplate applied unconditionally; connection pools (HikariCP/DBCP) that reset autoCommit=true when returning connections; mixing Spring @Transactional with manual commits on the same connection.
Related errors
- Cannot rollback in autocommit mode.
- Cannot change isolation level while transaction is active.
- Invalid transaction isolation level: ${level}
- SQLite only supports TYPE_FORWARD_ONLY cursors
- SQLite only supports CONCUR_READ_ONLY cursors
AI-assisted analysis of tursodatabase/turso@bad083fafb (2026-08-16).
Data as JSON: /api/errors/e742ecfddafbb0ee.
Report an issue: GitHub.