?? transactiontest.java
字號:
/* * TransactionTest.java * * Created on June 11, 2005, 12:42 AM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package ch03;import java.sql.*;import common.*;/** * * @author kevin */public class TransactionTest { public static void main(String[] args){ Connection connCommit = null; Connection connCommitRe = null; Statement stmt = null; Statement stmtRe = null; ResultSet rs = null; String sqlString = "insert into simple_tbl (id, name) values (100, \'insert data\')"; try{ ConnectionFactory factory = ConnectionFactory.getConnectionFactory(); connCommit = factory.getConnection(); connCommit.setTransactionIsolation(connCommit.TRANSACTION_READ_COMMITTED); connCommit.setAutoCommit(false); stmt = connCommit.createStatement(); connCommitRe = factory.getConnection(); connCommitRe.setTransactionIsolation(connCommitRe.TRANSACTION_SERIALIZABLE); connCommitRe.setAutoCommit(false); stmtRe = connCommit.createStatement(); rs = stmt.executeQuery("select id, name from simple_tbl"); display(rs); rs = stmtRe.executeQuery("select id, name from simple_tbl"); display(rs); System.out.println("insert data"); stmt.executeUpdate(sqlString); rs = stmt.executeQuery("select id, name from simple_tbl"); display(rs); rs = stmtRe.executeQuery("select id, name from simple_tbl"); display(rs); System.out.println("delete from tab"); stmt.executeUpdate("delete from simple_tbl where id=1"); rs = stmt.executeQuery("select id, name from simple_tbl"); display(rs); rs = stmtRe.executeQuery("select id, name from simple_tbl"); display(rs); connCommit.rollback(); connCommitRe.rollback(); }catch(SQLException e){ ExportSQLInfo.showSQLException(e); }catch(Exception e){ e.printStackTrace(); } finally{ DBUtils.close(rs,stmt,connCommit); DBUtils.close(stmtRe, connCommitRe); } } public static void display(ResultSet rs){ try{ while(rs.next()){ long id = rs.getLong("id"); String name = rs.getString("name"); System.out.println("ID: " + id + " NAME: " + name); } }catch(SQLException e){ ExportSQLInfo.showSQLException(e); }finally{ DBUtils.close(rs); } } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -