日期:2014-05-16 浏览次数:20479 次
Connection lock = getConnection(); lock.setAutoCommit(false); lock.createStatement().execute("select * from zhaojianyong for update"); final Connection connection = getConnection(); connection.setAutoCommit(false); new Thread(){ @Override public void run() { try { Thread.sleep(10 * 1000); } catch (InterruptedException ex) { ex.printStackTrace(); } try { System.out.println("begin commit"); connection.commit(); System.out.println("end commit"); } catch (SQLException ex) { ex.printStackTrace(); } } }.start(); connection.createStatement().execute("update zhaojianyong set id= 8 where id != 0");