In a database system where more than one transaction is being executed simultaneously and in parallel, the property of isolation states that all the transactions will be carried out and executed as if it is the only transaction in the system. No transaction will affect the existence of any other transaction.
JDBC provides support 5 transaction isolation levels through Connection interface.
The setTransactionIsolation() method of the Connection interface is used to change the transaction isolation level for the current connection.
This method accepts an integer value representing one of the 5 transaction isolation levels.
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Connection_setTransactionIsolation { public static void main(String args[]) throws SQLException { //Registering the Driver DriverManager.registerDriver(new com.mysql.jdbc.Driver()); //Getting the connection String url = "jdbc:mysql://localhost/mydatabase"; Connection con = DriverManager.getConnection(url, "root", "password"); System.out.println("Connection established......"); //Retrieving the transaction isolation level con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); int transactionIsoltionLevel = con.getTransactionIsolation(); System.out.println("Transaction isolation level of the underlying database is: "+transactionIsoltionLevel); } }
Connection established...... Transaction isolation level of the underlying database is: 1