JDBC resource release details

    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 ();
}
}

Written two

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();
        }
    }

Please Gangster two pointing error code

Guess you like

Origin www.cnblogs.com/ITRonion/p/12346060.html