O'Reilly logo

Java Programming with Oracle SQLJ by Jason Price

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.4. A Transaction Isolation Level Example

I will now guide you through an example showing how the different transaction isolation levels work. In this example, you'll see the effect of transaction isolation levels on two connection contexts that access the same rows in the customers table. Initially, the customers table contains the following rows:

id first_name last_name  dob         phone
-- ---------- ---------- ----------- ------------
 1 John       Smith      01-JAN-1965 650-555-1212
 2 Cynthia    Stevens    05-MAR-1968 650-555-1213
 3 Steve      Seymour    16-JUN-1971 650-555-1214
 4 Gail       Williams   01-DEC-1975 650-555-1215
 5 Doreen     Heyson     20-AUG-1970 650-555-1216

I use two connection contexts in this example: mod_context to modify the data in the table, and ser_context to demonstrate the effect of the SERIALIZABLE transaction isolation level on the visibility of those modifications from other transactions. The following code creates the two connection contexts:

// create a connection context named mod_context
DefaultContext mod_context = Oracle.getConnection(
  "jdbc:oracle:thin:@localhost:1521:orcl",
  "fundamental_user",
  "fundamental_password"
);

// create a connection context named ser_context
DefaultContext ser_context = Oracle.getConnection(
  "jdbc:oracle:thin:@localhost:1521:orcl",
  "fundamental_user",
  "fundamental_password"
);

Both connection contexts initially have the default Oracle transaction isolation level of READ COMMITTED. The following statement changes the transaction isolation level for ser_context ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required