Java Reference
In-Depth Information
When you create a new Connection object, its transaction isolation level is usually set
to the default for the underlying database. You can call the method setIsolationLevel
to change the transaction isolation level, and the new level is in effect for the rest of
the connection session.
You can also change the transaction isolation level for just one transaction by setting
it before the transaction begins and resetting it after the transaction ends.
Changing the transaction isolation level during a transaction is not
usually recommended because it triggers an immediate call to the
commit method, causing any changes up to that point to be made
permanent.
Caution
Transaction Savepoints
Transaction savepoints are JDBC 3.0 enhancements that offer finer control over
transaction commit and rollback. During a transaction, a named savepoint may be
inserted between operations to act as a marker, so that the transaction may be rolled
back to that marker, leaving all of the operations before the marker in effect.
The following example shows a Savepoint being set after the first update, and the
transaction being rolled back to that Savepoint, removing two subsequent updates.
(The arguments update1, update2 and update3 represent SQL commands.)
con.setAutoCommit(false);
Statement stmt = con.createStatement();
stmt.executeUpdate(update1);
Savepoint savePoint1 = con.setSavepoint("SavePoint1");
stmt.executeUpdate(update2);
stmt.executeUpdate(update3);
con.rollback(savePoint1);
con.commit();
Multithreading
The JDBC specifications require that operations on all the java.sql objects be thread
safe. This means that they must be able to handle a situation where several threads
call the same object simultaneously. Some drivers may provide this full concurrency,
and others may execute one statement and wait until it completes before sending the
next.
Search WWH ::




Custom Search