Chapter 13. JDBC and SQLJ global transaction support
JDBC and SQLJ global transaction support lets Enterprise Java Beans (EJB) and
Java servlets that run under WebSphere Application Server 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 Database for Linux, UNIX, and
Windows.
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. As the following code shows, 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.
In contrast, applications cannot call the commit, rollback,orsetAutoCommit(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.
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
...
Figure 59. Example of a local transaction
© Copyright IBM Corp. 1998, 2008 473
|
|
|
|
|