在我们的代码中,我们通常使用以下模式:
Connection conn;
try{
conn = getConnection();
//Do databasey stuff
}catch(Exceptions that get thrown){
}finally{
try{
conn.close();
}catch(SQLException ex){
logger.error("Failed to cleanup database connection",ex);
}
}
但是 findbugs 不喜欢这样。由于 conn.close() 可以抛出异常,因此不能保证关闭连接。findbugs 是否过于迂腐,或者是否有更好的方法来关闭数据库连接。
编辑:添加了删除的 try catch 关闭。