Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading