我有这样的代码:
public static MyObject forId(long myObjectId, Connection cxn) throws SQLException {
try (PreparedStatement stmt = cxn.prepareStatement(selectMyObjectById))) {
stmt.setLong(1, myObjectId);
try (ResultSet res = stmt.executeQuery()) {
res.next();
return MyObject.fromResultSet(res);
}
}
}
SpotBugs 将其识别为OBL_UNSATISFIED_OBLIGATION
JDBC Statement 对象。这是误报吗?我的印象是 try-with-resources 将确保这些资源在所有情况下都能正确关闭。