Committing Or Rolling Back Jdbc Transactions; Default Jdbc Autocommit Modes - IBM DB2 Manual

Table of Contents

Advertisement

Committing or rolling back JDBC transactions

In JDBC, to commit or roll back transactions explicitly, use the commit or rollback
methods.
For example:
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.

Default JDBC autocommit modes

The default autocommit mode depends on the data source to which the JDBC
application connects.
Autocommit default for DB2 data sources
For connections to DB2 data sources, the default autocommit mode is true.
Autocommit default for IDS data sources
For connections to IDS data sources, the default autocommit mode depends on the
type of data source. The following table shows the defaults.
Table 19. Default autocommit modes for IDS data sources
Type of data source
ANSI-compliant database
Non-ANSI-compliant
database without logging
74
Application Programming Guide and Reference for Java
Connection con;
...
Related concepts
"JDBC connection objects" on page 19
"Savepoints in JDBC applications" on page 57
Related tasks
"Making batch updates in JDBC applications" on page 28
"Disconnecting from data sources in JDBC applications" on page 99
Default autocommit mode
for local transactions
true
false
Default autocommit mode
for global transactions
false
not applicable

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents