Basil Bourque
Basil Bourque

Reputation: 340290

Turn off AUTOCOMMIT in H2 Database Engine via SQL rather than via Java method

How can I turn off AUTOCOMMIT in H2 via SQL?

I want to start a transaction while using H2 from JDBC. I understand that in JDBC we do not use BEGIN TRANSACTION calls in SQL. Instead we merely disable auto-commit.

So how to turn off auto-commit in a JDBC session with H2?

I see some setAutoCommit( boolean ) methods on classes such as Session. Must I use one of those as a Java call?

Is there some SQL statement that I can use in my embedded SQL in my JDBC code?

Upvotes: 1

Views: 1352

Answers (1)

xerx593
xerx593

Reputation: 13299

SET AUTOCOMMIT OFF ;

(as i see,) You have three options:

  • via jdbc url, like: jdbc:h2:./foo/bar;AUTOCOMMIT=OFF
  • via SQL statement: SET AUTOCOMMIT OFF (possible values: TRUE | ON | FALSE | OFF, not supported in cluster mode)
  • via (java.sql/)Connection.setAutoCommit(false)

Refs:

Upvotes: 2

Related Questions