Databases Reference
In-Depth Information
Example 5-22 Setting islolation level
Connection con = null;
Class.forName(“com.ibm.db2.jcc.DB2Driver”).newInstance();
con = DriverManager.getConnection(“jdbc:db2:sample”);
// Set the isolation level to RR
con.setTransactionIsolation(TRANSACTION_SERIALIZABLE);
Table 5-1 show the JDBC equivalent variable for the different isolation levels.
Table 5-1 Equivalent JDBC and DB2 isolation levels
JDBC integer constant value
DB2 isolation level
Equivalent
integer
value
TRANSACTION_SERIALIZABLE
Repeatable read
8
TRANSACTION_REPEATABLE_READ
Read stability
4
TRANSACTION_READ_COMMITTED
Cursor stability
2
TRANSACTION_READ_UNCOMMITTED
Uncommitted read
1
5.10.3 Savepoints
A savepoint defines a particular state of the database during a unit of work or
transaction. A savepoint is required if we want to roll back the transaction to a
particular state instead of rolling back to the start of the transaction. DB2
Universal driver provides the method set Savepoint of the Connection object to
set a savepoint during the transaction.
A savepoint can be release by calling the method releaseSavePoint method of
the Connection object. Releasing a savepoint will release all the savepoints
created after the released savepoint. After releasing the savepoint, the
transaction cannot be rolled back to the released savepoint or any of the
savepoints created subsequently.
A transaction can be rolled back to a savepoint by calling the rollback method
and giving the savepoint variable as an argument to this method.
Any cursor opened inside a savepoint will remain open even after rollback to the
savepoint but can go to an invalid state if they depend on some DDL statements
which were rolled back.
Example 5-23 on page 238 shows how to create the savepoint.
Search WWH ::




Custom Search