Skip to content

Commit 2a5c4e7

Browse files
committed
[java] Using try-with-resources to automatically close prepared statements
1 parent d7a3443 commit 2a5c4e7

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

java/server/src/org/openqa/selenium/grid/sessionmap/jdbc/JdbcBackedSessionMap.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ public static SessionMap create(Config config) {
8989
public boolean add(Session session) {
9090
Require.nonNull("Session to add", session);
9191

92-
try {
93-
return insertSessionStatement(session).executeUpdate() >= 1;
94-
92+
try (PreparedStatement statement = insertSessionStatement(session)) {
93+
return statement.executeUpdate() >= 1;
9594
} catch (SQLException e) {
9695
throw new JdbcException(e);
9796
}
@@ -105,7 +104,7 @@ public Session get(SessionId id) throws NoSuchSessionException {
105104
Capabilities caps = null;
106105
String rawUri = null;
107106

108-
try (ResultSet sessions = readSessionStatement(id).executeQuery()){
107+
try (PreparedStatement statement = readSessionStatement(id); ResultSet sessions = statement.executeQuery()) {
109108
if (!sessions.next()) {
110109
throw new NoSuchSessionException("Unable to find...");
111110
}

0 commit comments

Comments
 (0)