Autocommit behavior The JDBC specification requires that, by default, a COMMIT is performed after each data modification statement. Currently, the server-side JDBC behavior is to commit. You can control this behavior using a statement such as the following:
conn.setAutoCommit( false ) ;
where conn is the current connection object.
Connection defaults From server-side JDBC, only the first call to getConnection( "jdbc:default:connection" ) creates a new connection with the default values. Subsequent calls return a wrapper of the current connection with all connection properties unchanged. If you set AutoCommit to OFF in your initial connection, any subsequent getConnection calls within the same Java code return a connection with AutoCommit set to OFF.
You may wish to ensure that closing a connection resets connection properties to their default values, so subsequent connections are obtained with standard JDBC values. The following type of code achieves this:
Connection conn = DriverManager.getConnection(""); boolean oldAutoCommit = conn.getAutoCommit(); try { // do code here } finally { conn.setAutoCommit( oldAutoCommit ); }
This discussion applies not only to AutoCommit, but also to other connection properties such as TransactionIsolation and is ReadOnly.