javaweb通用事务
1 //事务管理 2 public void executeTran(String[] sql){ 3 Connection connection = getConnection(); 4 PreparedStatement pstmt = null; 5 6 try { 7 //开启自动提交 8 connection.setAutoCommit(false); 9 //预编译sql 10 for (int i = 0; i <sql.length; i++) { 11 pstmt= connection.prepareStatement(sql[i]); 12 pstmt.executeUpdate(); 13 } 14 } catch (SQLException e) { 15 e.printStackTrace(); 16 } 17 }

浙公网安备 33010602011771号