JDBC 释放资源细节问题

    public static void Close(ResultSet rs, PreparedStatement pstmt, Connection conn) {
try {
if (rs != null) {  //ResultSet对象
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (pstmt != null) {  //PreparedStatement对象
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}

try {
if (conn != null) { //Connection对象
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}

写法二

public static void Close(ResultSet rs, PreparedStatement pstmt, Connection conn) {
        try {
            if (rs != null) {   //ResultSet对象
                rs.close();
            }
            if (pstmt != null) {    //PreparedStatement对象
                rs.close();
            }
            if (conn != null) {     //Connection对象
                rs.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

请大佬指点两处代码的错误

上一篇:JDBC


下一篇:Mybatis是什么?