Connection: getAutoCommit() : Connection « java.sql « Java by API






Connection: getAutoCommit()

  

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

public class Main {

  public static void main(String[] args) {
    Connection conn = null;
    Statement stmt = null;
    boolean executeResult;
    try {
      String driver = "oracle.jdbc.driver.OracleDriver";
      Class.forName(driver).newInstance();
      System.out.println("Connecting to database...");
      String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:ORCL";
      conn = DriverManager.getConnection(jdbcUrl, "yourName", "mypwd");
      stmt = conn.createStatement();
      conn.setAutoCommit(false);
      if (!conn.getAutoCommit())
        System.out.println("Auto-commit is set to false");
      String sql = "INSERT INTO Location VALUES(715,'Houston')";
      stmt.executeUpdate(sql);
      sql = "INSERT INTO Employees VALUES" + "(8,'K','4351',{d '2000-02-00'},715)";
      stmt.executeUpdate(sql);
      conn.commit();
    } catch (SQLException se) {
      String msg = se.getMessage();
      msg = "SQLException occured with message: " + msg;
      System.out.println(msg);
      System.out.println("Starting rollback operations...");
      try {
        conn.rollback();
      } catch (SQLException se2) {
        se2.printStackTrace();
      }
    } catch (Exception e) {
      e.printStackTrace();
    } 
  }
}

   
    
  








Related examples in the same category

1.Connection.TRANSACTION_NONE
2.Connection.TRANSACTION_READ_COMMITTED
3.Connection.TRANSACTION_READ_UNCOMMITTED
4.Connection.TRANSACTION_REPEATABLE_READ
5.Connection.TRANSACTION_SERIALIZABLE
6.Connection: close()
7.Connection: commit()
8.Connection: createStatement()
9.Connection: createStatement(int resultSetType, int resultSetConcurrency)
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)