Committing a unit of work

When using JDBC or SQLJ, applications can issue connection.commit() and rollback() method calls to coordinate multiple data source updates. When using type 4 connectivity, these updates are independent of the CICS unit of work. However, when using type 2 connectivity, the IBM®® Data Server Driver for JDBC and SQLJ converts these calls into a JCICS commit or a JCICS rollback call, resulting in a CICS syncpoint being taken.

About this task

With JDBC type 2 connectivity a JDBC or SQLJ commit results in the whole CICS unit of work being committed, not just the updates made to Db2®®. CICS does not support committing work done using a JDBC type 2 connection independently of the rest of the CICS unit of work. 

A JDBC or SQLJ application can also issue JCICS commit or rollback directly, and this has the same result as issuing a JDBC or SQLJ commit or rollback method call. The whole unit of work is committed or rolled back together, both Db2 updates and updates to CICS controlled resources.

When you are working with JDBC connections, there are some circumstances which cause the unit of work to be committed when the connection is closed. This applies in either of the following circumstances:
  • Any use of a Liberty type 2 DataSource.
  • Use of the autocommit=true property. See Autocommit.
  • Use of the DriverManager interface with an explicit URL.

For a standalone application, these rules do not cause a problem, as CICS ensures that an end of task syncpoint is taken in addition to any syncpoint that is taken when the connection is closed. However, if you have a number of programs that make up an application, one program might access Db2, then link to another program that also accesses Db2, in the course of the same unit of work. If you want any of these programs to be Java™ programs that use JDBC or SQLJ, you need to ensure that the unit of work is not committed when the JDBC connection to Db2 is closed, or else the application will not operate as planned. You should be particularly aware of this requirement if you are using the Liberty DataSource, as the Liberty connection pool will automatically close and cleanup any connections when the Java application terminates. See Syncpoint issues for Liberty DataSources for more information.

To address this issue, you can use either of the following options, which allow the unit of work not to be committed when the JDBC connection is closed.
  • A DriverManager with default URL in an OSGi or Liberty JVM server.
  • A CICS DataSource using the cicsts:jdbc-1.0 feature in a Liberty JVM server.