在JIVE中,为什么它从来不关闭RESULTSET呢???

03-06-02 uu_snow
比如在DbAuthorizationFactory.java中有:
public Authorization createAuthorization(String username, String password)
throws UnauthorizedException
{
if (username == null || password == null) {
throw new UnauthorizedException();
}
//Jive stores all passwords in hashed form. So, hash the plain text
//password for comparison.
password = StringUtils.hash(password);
long userID = 0;
Connection con = null;
PreparedStatement pstmt = null;
try {
con = ConnectionManager.getConnection();
pstmt = con.prepareStatement(AUTHORIZE);
pstmt.setString(1, username);
pstmt.setString(2, password);

ResultSet rs = pstmt.executeQuery();
//If the query had no results, the username and password
//did not match a user record. Therefore, throw an exception.
if (!rs.next()) {
throw new UnauthorizedException();
}
userID = rs.getLong(1);
}
catch( SQLException sqle ) {
System.err.println("Exception in DbAuthorizationFactory:" + sqle);
sqle.printStackTrace();
throw new UnauthorizedException();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
//Got this far, so the user must be authorized.
return new DbAuthorization(userID);
}

它没有关闭RESULTSET
这样可以吗?

thinkman
2003-06-03 15:37
创建ResultSet的Statement关闭之后,ResultSet会自动关闭

uu_snow
2003-06-03 17:03
那就是说,只要我保证把
PrepareStatement或Statement
关闭了
就不用在程序里写rs.close了?

thinkman
2003-06-03 18:06
yes

猜你喜欢