Committing or rolling back JDBC transactions

In JDBC, to commit or roll back transactions explicitly, use the commit or rollback methods.

About this task

For example:
 Connection con;
 …
con.commit();

If autocommit mode is on, the database manager performs a commit operation after every SQL statement completes. To set autocommit mode on, invoke the Connection.setAutoCommit(true) method. To set autocommit mode off, invoke the Connection.setAutoCommit(false) method. To determine whether autocommit mode is on, invoke the Connection.getAutoCommit method.

Connections that participate in distributed transactions cannot invoke the setAutoCommit(true) method.

When you change the autocommit state, the database manager executes a commit operation, if the application is not already on a transaction boundary.

While a connection is participating in a distributed or global transaction, the associated application cannot issue the commit or rollback methods.

While a connection is participating in a global transaction, the associated application cannot invoke the setAutoCommit(true) method.