From 2a5c4e707012da14ce04738ec3be8763ab3ba4af Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Tue, 16 Jun 2020 21:44:40 +0300 Subject: [PATCH] [java] Using try-with-resources to automatically close prepared statements --- .../grid/sessionmap/jdbc/JdbcBackedSessionMap.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/java/server/src/org/openqa/selenium/grid/sessionmap/jdbc/JdbcBackedSessionMap.java b/java/server/src/org/openqa/selenium/grid/sessionmap/jdbc/JdbcBackedSessionMap.java index 76b30b157db36..6ad859f077573 100644 --- a/java/server/src/org/openqa/selenium/grid/sessionmap/jdbc/JdbcBackedSessionMap.java +++ b/java/server/src/org/openqa/selenium/grid/sessionmap/jdbc/JdbcBackedSessionMap.java @@ -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); } @@ -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..."); }