我正在尝试使用FindBugs来检测连接泄漏,但在以下两种情况下它无法执行此操作。
public static int getSeq(Integer id) throws FatalException {
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection con = null;
int commentSeq = 0;
try {
con = JDBCUtil.getConnection();
pstmt = con.prepareStatement(GET_NEXT_COMMENT_ID);
pstmt.setInt(1, id.intValue());
rs = pstmt.executeQuery();
if (rs.next()) {
commentSeq = new Integer(rs.getInt(1)).intValue();
return commentSeq;
}
} catch (SQLException e) {
logError("getNextId", e);
} finally {
close(rs, pstmt);
}
return commentSeq;
}
public void someMethod() {
con = JDBCUtil.getConnection();
doSomethingWithDb(con);
//No Closing of the connection, but findbug does not complain
}