connection 关闭方法

来源:互联网 发布:sql 随机选取 编辑:程序博客网 时间:2024/05/22 04:25

Connection conn = null;
ResultSet rs = null;
preparedStatement pss = null;
try
{
        conn = dataSource.getConnection(USERID,pASSWORD);
        pss = conn.prepareStatement("SELECT SAVESERIALZEDDATA FROM SESSION.pINGSESSION3DATA WHERE SESSIONKEY = ?");
        pss.setString(1,sessionKey);
        rs = pss.executeQuery();
        pss.close();
        conn.close();
}
catch (Throwable t)
{
        // Insert Appropriate Error Handling Here
}
finally
{
        // The finally clause is always executed - even in error
        // conditions preparedStatements and Connections will always be closed
        try
        {
                  if (pss != null)
                              pss.close();
        }
        catch(Exception e) {}
        try
        {
                  if (conn != null)
                              conn.close();
        }
        catch (Exception e){}
        }
}