Fix potentially unreleased DB resources in test code
@@ -42,21 +42,22 @@ public class DatabaseClient {
}
public void runQuery(String query, Consumer<ResultSet> consumer) throws SQLException {
- ResultSet rs = connection.prepareStatement(query).executeQuery();
+ try (ResultSet rs = connection.prepareStatement(query).executeQuery()) {
while (rs.next()) {
consumer.accept(rs);
}
}
+ }
public int count(String table) throws SQLException {
String query = String.format("select count(*) as count from %s", table);
- ResultSet rs = connection.prepareStatement(query).executeQuery();
-
+ try (ResultSet rs = connection.prepareStatement(query).executeQuery()) {
while (rs.next()) {
return rs.getInt("count");
}
+ }
return 0;
}
