我在我们的代码库上运行了 findbugs,它指出还有两个语句需要关闭。在这部分代码中,我们运行:
preparedStatement = connection.prepareStatement(query);
对于 3 个不同的查询,重用preparedStatement。在 finally 块中,我们确实关闭了资源:
finally{
try{
if (resultSet != null)
resultSet.close();
} catch (Exception e) {
exceptionHandler.ignore(e);
}
try {
if (preparedStatement != null)
preparedStatement.close();
} catch(Exception e) {
exceptionHandler.ignore(e);
}
该语句是否应该在下一个 connection.prepareStatement(query) 之前关闭 还是这个 findbugs 很谨慎?