JDBC资源释放

关闭顺序:

ResultSet => Statement => Connection

 

 1     private void release(ResultSet rs, Statement stmt, Connection conn) {
 2         if (rs!=null){
 3             try {
 4                 rs.close();
 5             }catch (SQLException e){
 6                 e.printStackTrace();
 7             }
 8         }
 9 
10         if (stmt!=null){
11             try {
12                 stmt.close();
13             }catch (SQLException e1){
14                 e1.printStackTrace();
15             }
16         }
17         
18         if (conn!=null){
19             try {
20                 conn.close();
21             }catch (SQLException e2){
22                 e2.printStackTrace();
23             }
24         }
25     }

 

posted @ 2020-04-02 11:06  齐天大猫呀  阅读(108)  评论(0)    收藏  举报