Example Of A Distributed Transaction That Uses Jta Methods - IBM DB2 Manual

Table of Contents

Advertisement

SYSIBM.INDOUBT table and the T4XAIndbtPkg package. You should never
modify the SYSIBM.INDOUBT table manually.
In JDBC or SQLJ applications, distributed transactions are supported for
connections that are established using the DataSource interface. A connection is
normally established by the application server.

Example of a distributed transaction that uses JTA methods

Distributed transactions typically involve multiple connections to the same data
source or different data sources, which can include data sources from different
manufacturers.
The best way to demonstrate distributed transactions is to contrast them with local
transactions. With local transactions, a JDBC application makes changes to a
database permanent and indicates the end of a unit of work in one of the
following ways:
v By calling the Connection.commit or Connection.rollback methods after
v By calling the Connection.setAutoCommit(true) method at the beginning of the
Figure 56 outlines code that executes local transactions.
con1.setAutoCommit(false); // Set autocommit off
// execute some SQL
...
con1.commit();
// execute some more SQL
...
con1.rollback();
con1.setAutoCommit(true);
...
// Execute some more SQL, which is automatically committed after
// every SQL statement.
Figure 56. Example of a local transaction
In contrast, applications that participate in distributed transactions cannot call the
Connection.commit, Connection.rollback, or Connection.setAutoCommit(true)
methods within the distributed transaction. With distributed transactions, the
Connection.commit or Connection.rollback methods do not indicate transaction
boundaries. Instead, your applications let the application server manage
transaction boundaries.
Figure 57 on page 469 demonstrates an application that uses distributed
transactions. While the code in the example is running, the application server is
also executing other EJBs that are part of this same distributed transaction. When
all EJBs have called utx.commit(), the entire distributed transaction is committed
by the application server. If any of the EJBs are unsuccessful, the application server
rolls back all the work done by all EJBs that are associated with the distributed
468
Application Programming Guide and Reference for Java
Related concepts
Chapter 13, "JDBC and SQLJ global transaction support," on page 473
Related reference
"DB2T4XAIndoubtUtil for distributed transactions with DB2 UDB for OS/390
and z/OS Version 7 servers" on page 428
executing one or more SQL statements
application to commit changes after every SQL statement
// Commit the transaction
// Roll back the transaction
// Enable commit after every SQL statement

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents