Class.forName(driver).newInstance();
connection = DriverManager.getConnection(url,username,password);
DriverManager.setLogStream(System.out); // for debuging
connection.setAutoCommit(false);
//create a statement
stmt = connection.createStatement();
//execute a query
stmt.executeUpdate("insert into tickets values ('ivana', 'NY', 'BOSTON', '11-July-2002', '9:00 AM', 'Delta 782')");
stmt.executeUpdate("insert into tickets values ('ivana', 'BOSTON', 'CANCUN', '11-July-2002', '12:00 PM', 'Delta 819')");
txpoint = connection.setSavepoint("oneway"); // establish a save point
stmt.executeUpdate("insert into tickets values ('ivana', 'CANCUN', 'NY', '12-August-2002', '2:00 PM', 'Delta 820')");
stmt.executeUpdate("insert into tickets values ('ivana', 'NY', 'BOSTON', '12-August-2002', '6:00 PM', 'Delta 783')");
// for demo purposes in case there are no exceptions
if (forseoneway && (txpoint != null) )
connection.rollback(txpoint);
connection.commit();
setTransactionIsolation
connection = DriverManager.getConnection(url,username,password);
DriverManager.setLogStream(System.out); // for debuging
connection.setAutoCommit(false);
//create a statement
stmt = connection.createStatement();
//execute a query
stmt.executeUpdate("insert into tickets values ('ivana', 'NY', 'BOSTON', '11-July-2002', '9:00 AM', 'Delta 782')");
stmt.executeUpdate("insert into tickets values ('ivana', 'BOSTON', 'CANCUN', '11-July-2002', '12:00 PM', 'Delta 819')");
txpoint = connection.setSavepoint("oneway"); // establish a save point
stmt.executeUpdate("insert into tickets values ('ivana', 'CANCUN', 'NY', '12-August-2002', '2:00 PM', 'Delta 820')");
stmt.executeUpdate("insert into tickets values ('ivana', 'NY', 'BOSTON', '12-August-2002', '6:00 PM', 'Delta 783')");
// for demo purposes in case there are no exceptions
if (forseoneway && (txpoint != null) )
connection.rollback(txpoint);
connection.commit();
setTransactionIsolation