使用FindBugs检测连接泄漏

时间:2014-06-05 22:10:19

标签: java findbugs

我正在尝试使用FindBugs来检测连接泄漏,但在以下两种情况下它无法执行此操作。

场景1

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

场景2

public void someMethod() {
    con = JDBCUtil.getConnection();
    doSomethingWithDb(con);
    //No Closing of the connection, but findbug does not complain
}

0 个答案:

没有答案