JDBC and SQLJ global transaction support

JDBC and SQLJ global transaction support lets Enterprise Java Beans (EJB) and Java servlets access Db2 for z/OS® relational data within global transactions.

WebSphere® Application Server provides the environment to deploy EJBs and servlets, and RRS provides the transaction management.

JDBC and SQLJ global transaction support provides similar function to JDBC and SQLJ distributed transaction support. However, JDBC and SQLJ distributed transaction support is available with IBM® Data Server Driver for JDBC and SQLJ type 4 connectivity on Db2 for z/OS or Db2.

You can use global transactions in JDBC or SQLJ applications. Global transactions are supported for connections that are established using the DriverManager or the DataSource interface.

The best way to demonstrate global transactions is to contrast them with local transactions. With local transactions, you call the commit or rollback methods of the Connection class to make the changes to the database permanent and indicate the end of each unit or work. Alternatively, you can use the setAutoCommit(true) method to perform a commit operation after every SQL statement. The following code shows an example of a local transaction.

con1.setAutoCommit(false);  // Set autocommit off
// execute some SQL
…
con1.commit();              // Commit the transaction
// execute some more SQL
…
con1.rollback();            // Roll back the transaction
con1.setAutoCommit(true);   // Enable commit after every SQL statement
…

In contrast, applications cannot call the commit, rollback, or setAutoCommit(true) methods on the Connection object when the applications are in a global transaction. With global transactions, the commit or rollback methods on the Connection object do not indicate transaction boundaries. Instead, your applications let WebSphere manage transaction boundaries. Alternatively, you can use Db2-customized Java Transaction API (JTA) interfaces to indicate the boundaries of transactions. Although Db2 for z/OS does not implement the JTA specification, the methods for delimiting transaction boundaries are available with the JDBC driver. The following code demonstrates the use of the JTA interfaces to indicate global transaction boundaries.

javax.transaction.UserTransaction utx;
// Use the begin method on a UserTransaction object to indicate
// the beginning of a global transaction.
utx.begin();
…
// Execute some SQL with one Connection object.
// Do not call Connection methods commit or rollback.
…
// Use the commit method on the UserTransaction object to
// drive all transaction branches to commit and indicate
// the end of the global transaction.
utx.commit();
…