Loading

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     }

 

posted @ 2020-04-23 02:29  Rzk  阅读(202)  评论(0)    收藏  举报