{"record":{"id":"e742ecfddafbb0ee","repo":"tursodatabase/turso","slug":"cannot-commit-in-autocommit-mode","errorCode":null,"errorMessage":"Cannot commit in autocommit mode.","messagePattern":"Cannot commit in autocommit mode\\.","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/core/TursoConnection.java","lineNumber":220,"sourceCode":"   *\n   * @return true if auto-commit mode is enabled; false otherwise\n   * @throws SQLException if a database access error occurs or the connection is closed\n   */\n  public boolean getAutoCommit() throws SQLException {\n    checkOpen();\n    return autoCommit;\n  }\n\n  /**\n   * Commits the current transaction.\n   *\n   * @throws SQLException if in auto-commit mode, closed, or database error occurs.\n   */\n  public void commit() throws SQLException {\n    synchronized (transactionLock) {\n      checkOpen();\n      if (autoCommit) {\n        throw new SQLException(\"Cannot commit in autocommit mode.\");\n      }\n\n      if (inTransaction) {\n        executeInternal(\"COMMIT\");\n        inTransaction = false;\n      }\n    }\n  }\n\n  /**\n   * Rolls back the current transaction.\n   *\n   * @throws SQLException if in auto-commit mode, closed, or database error occurs.\n   */\n  public void rollback() throws SQLException {\n    synchronized (transactionLock) {\n      checkOpen();\n      if (autoCommit) {","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/bindings/java/src/main/java/tech/turso/core/TursoConnection.java#L202-L238","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconn.commit(); // throws: autoCommit is still true\n\n// after\nconn.setAutoCommit(false);\ntry (Statement st = conn.createStatement()) {\n  st.executeUpdate(\"UPDATE t SET a = 1\");\n  conn.commit();\n}","handlingStrategy":"validation","validationCode":"if (conn.getAutoCommit()) {\n  // autocommit mode: every statement already committed — nothing to do\n} else {\n  conn.commit();\n}","typeGuard":null,"tryCatchPattern":"try {\n  conn.commit();\n} catch (SQLException e) {\n  if (\"Cannot commit in autocommit mode.\".equals(e.getMessage())) {\n    // benign: no transaction was open\n  } else {\n    throw e;\n  }\n}","preventionTips":["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"],"tags":["java","jdbc","transaction","autocommit","bindings"],"backgroundTag":"commit-in-autocommit-mode","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}