Skip to content

Commit

Permalink
[java] Using try-with-resources to automatically close prepared state…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
barancev committed Jun 16, 2020
1 parent d7a3443 commit 2a5c4e7
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ public static SessionMap create(Config config) {
public boolean add(Session session) {
Require.nonNull("Session to add", session);

try {
return insertSessionStatement(session).executeUpdate() >= 1;

try (PreparedStatement statement = insertSessionStatement(session)) {
return statement.executeUpdate() >= 1;
} catch (SQLException e) {
throw new JdbcException(e);
}
Expand All @@ -105,7 +104,7 @@ public Session get(SessionId id) throws NoSuchSessionException {
Capabilities caps = null;
String rawUri = null;

try (ResultSet sessions = readSessionStatement(id).executeQuery()){
try (PreparedStatement statement = readSessionStatement(id); ResultSet sessions = statement.executeQuery()) {
if (!sessions.next()) {
throw new NoSuchSessionException("Unable to find...");
}
Expand Down

0 comments on commit 2a5c4e7

Please sign in to comment.