Sun Java System Application Server Platform Edition 8.1 2005Q2 Update 2 Developer's Guide

- Previous: Using Non-Transactional Connections
- Next: Configurations for Specific JDBC Drivers

## Using JDBC Transaction Isolation Levels

For general information about transactions, see Chapter 12, Using the Transaction Serviceand the Sun Java System Application Server Platform Edition 8.1 2005Q2 Update 2 Administration Guide. For information about last agent optimization, which can improve performance, see Transaction Scope.

Not all database vendors support all transaction isolation levels available in the JDBC API. The Application Server permits specifying any isolation level your database supports. The following table defines transaction isolation levels.

Table 11–1 Transaction Isolation Levels

Transaction Isolation Level | Description
--- | ---
`TRANSACTION_READ_UNCOMMITTED` | Dirty reads, non-repeatable reads and phantom reads can occur.
`TRANSACTION_READ_COMMITTED` | Dirty reads are prevented; non-repeatable reads and phantom reads can occur.
`TRANSACTION_REPEATABLE_READ` | Dirty reads and non-repeatable reads are prevented; phantom reads can occur.
`TRANSACTION_SERIALIZABLE` | Dirty reads, non-repeatable reads and phantom reads are prevented.

Note that you cannot call `setTransactionIsolation()` during a transaction.

You can set the default transaction isolation level for a JDBC connection pool. For details, see Creating a Connection Pool.

To verify that a level is supported by your database management system, test your database programmatically using the `supportsTransactionIsolationLevel()` method in `java.sql.DatabaseMetaData`, as shown in the following example:

    java.sql.DatabaseMetaData db;
    if (db.supportsTransactionIsolationLevel(TRANSACTION_SERIALIZABLE)
       { Connection.setTransactionIsolation(TRANSACTION_SERIALIZABLE); }

For more information about these isolation levels and what they mean, see the JDBC 3.0 API specification.

Note –

Applications that change the isolation level on a pooled connection programmatically risk polluting the pool, which can lead to errors.

- Previous: Using Non-Transactional Connections
- Next: Configurations for Specific JDBC Drivers

- © 2010, Oracle Corporation and/or its affiliates