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 ...

Get Java Programming with Oracle SQLJ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.