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?
>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:
- http://www.h2database.com/html/commands.html#set_autocommit
- and http://www.h2database.com/html/advanced.html