zno2

conn,stmt,rset 的关闭(规范)

 

     Connection conn = null;
        Statement stmt = null;
        ResultSet rset = null;

        try {
            conn = dataSource.getConnection();
            stmt = conn.createStatement();
            rset = stmt.executeQuery("select 1 from dual");
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
             try { if (rset != null) rset.close(); } catch(Exception e) { }
             try { if (stmt != null) stmt.close(); } catch(Exception e) { }
             try { if (conn != null) conn.close(); } catch(Exception e) { }
        }

 

posted on 2016-08-06 07:25  zno2  阅读(367)  评论(0编辑  收藏  举报

导航