It depends on where you got this connection. If you created the connection yourself, there is no need to restore the automatic commit state.
, , , , , .
commit() auto commit. , JDBC commit() . commit() , , ( , rollback() , ).
[.]. , . dbcp , , , c3p0 , . , .
, , false , , . :
public <T> T withTransaction( TxCallback<T> closure ) throws Exception {
Connection conn = getConnection();
try {
boolean autoCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
T result = closure.call(conn);
conn.commit();
conn.setAutoCommit(autoCommit);
} catch( Exception e ) {
conn.rollback();
} finally {
conn.close();
}
}
, -.