Connection.TRANSACTION_READ_COMMITTED : Connection « java.sql « Java by API






Connection.TRANSACTION_READ_COMMITTED

  
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Main {
  public static void main(String[] args) throws Exception {
    int tx = conn.getMetaData().getDefaultTransactionIsolation();
    String txtxt=null;
    switch(tx) {
      case Connection.TRANSACTION_NONE :
        txtxt = "TRANSACTION_NONE"; break;
      case Connection.TRANSACTION_READ_COMMITTED :
        txtxt = "TRANSACTION_READ_COMMITTED"; break;
      case Connection.TRANSACTION_READ_UNCOMMITTED :
        txtxt = "TRANSACTION_READ_UNCOMMITTED"; break;
      case Connection.TRANSACTION_REPEATABLE_READ :
        txtxt = "TRANSACTION_REPEATABLE_READ"; break;
          case Connection.TRANSACTION_SERIALIZABLE :
        txtxt = "TRANSACTION_SERIALIZABLE"; break;
      default:
        txtxt = "UNKNOWN!!";
    }
    System.out.println(txtxt);
    conn.setTransactionIsolation(tx);
    System.out.println("Done");
    conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
    System.out.println("TX is now " + conn.getTransactionIsolation());
  }

  static Connection conn;

  static Statement st;

  static {
    try {
      // Step 1: Load the JDBC driver.
      Class.forName("org.hsqldb.jdbcDriver");
      System.out.println("Driver Loaded.");
      // Step 2: Establish the connection to the database.
      String url = "jdbc:hsqldb:data/tutorial";

      conn = DriverManager.getConnection(url, "sa", "");
      System.out.println("Got Connection.");

      st = conn.createStatement();
    } catch (Exception e) {
      System.err.println("Got an exception! ");
      e.printStackTrace();
      System.exit(0);
    }
  }
}

           
         
    
  








JDBCTransaction.zip( 596 k)

Related examples in the same category

1.Connection.TRANSACTION_NONE
2.Connection.TRANSACTION_READ_UNCOMMITTED
3.Connection.TRANSACTION_REPEATABLE_READ
4.Connection.TRANSACTION_SERIALIZABLE
5.Connection: close()
6.Connection: commit()
7.Connection: createStatement()
8.Connection: createStatement(int resultSetType, int resultSetConcurrency)
9.Connection: getAutoCommit()
10.Connection: getCatalog()
11.Connection: getMetaData()
12.Connection: getTransactionIsolation()
13.Connection: getWarnings()
14.Connection: nativeSQL(String sql)
15.Connection: prepareCall(String sql)
16.Connection: prepareStatement(String sql)
17.Connection: rollback()
18.Connection: rollback(Savepoint savepoint)
19.Connection: setAutoCommit(boolean autoCommit)
20.Connection: setSavepoint(String name)
21.Connection: setTransactionIsolation(int level)