Transaction Control In Sqlj Applications; Setting The Isolation Level For An Sqlj Transaction; Committing Or Rolling Back Sqlj Transactions - IBM DB2 Manual

Table of Contents

Advertisement

Example: Pass an arbitrary number of parameters of type Object, to a method that
inserts each parameter value into table TAB.
public void runThis(Object... objects) throws SQLException
{
}

Transaction control in SQLJ applications

In SQLJ applications, as in other types of SQL applications, transaction control
involves explicitly or implicitly committing and rolling back transactions, and
setting the isolation level for transactions.

Setting the isolation level for an SQLJ transaction

To set the isolation level for a unit of work within an SQLJ program, use the SET
TRANSACTION ISOLATION LEVEL clause.
The following table shows the values that you can specify in the SET
TRANSACTION ISOLATION LEVEL clause and their DB2 equivalents.
Table 23. Equivalent SQLJ and DB2 isolation levels
SET TRANSACTION value
SERIALIZABLE
REPEATABLE READ
READ COMMITTED
READ UNCOMMITTED
The isolation level affects the underlying JDBC connection as well as the SQLJ
connection.

Committing or rolling back SQLJ transactions

If you disable autocommit for an SQLJ connection, you need to perform explicit
commit or rollback operations.
You do this using execution clauses that contain the SQL COMMIT or ROLLBACK
statements.
To commit a transaction in an SQLJ program, use a statement like this:
#sql [myConnCtx] {COMMIT};
To roll back a transaction in an SQLJ program, use a statement like this:
#sql [myConnCtx] {ROLLBACK};
for (Object obj : objects)
{
#sql { INSERT INTO TAB (VARCHARCOL) VALUES(:obj) };
}
Related concepts
"SQL statement execution in SQLJ applications" on page 112
"JDBC connection objects" on page 19
Related reference
"SQLJ statement-clause" on page 288
"SQLJ SET-TRANSACTION-clause" on page 290
DB2 isolation level
Repeatable read
Read stability
Cursor stability
Uncommitted read
Chapter 4. SQLJ application programming
153

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents