Skip to content

Commit

Permalink
[java] Auto-closing a result set after use
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Aug 18, 2020
1 parent 3468f61 commit 49f2c2e
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,23 @@ public Session get(SessionId id) throws NoSuchSessionException {
span.setAttribute(DATABASE_STATEMENT, statement.toString());
span.setAttribute(DATABASE_OPERATION, "select");

ResultSet sessions = statement.executeQuery();
if (!sessions.next()) {
span.setAttribute("error", true);
span.setStatus(Status.NOT_FOUND);
span.addEvent("Session id does not exist in the database.", attributeValueMap);
try (ResultSet sessions = statement.executeQuery()) {
if (!sessions.next()) {
span.setAttribute("error", true);
span.setStatus(Status.NOT_FOUND);
span.addEvent("Session id does not exist in the database.", attributeValueMap);

throw new NoSuchSessionException("Unable to find...");
}
throw new NoSuchSessionException("Unable to find...");
}

rawUri = sessions.getString(SESSION_URI_COL);
String rawCapabilities = sessions.getString(SESSION_CAPS_COL);
rawUri = sessions.getString(SESSION_URI_COL);
String rawCapabilities = sessions.getString(SESSION_CAPS_COL);

caps = rawCapabilities == null ?
new ImmutableCapabilities() :
JSON.toType(rawCapabilities, Capabilities.class);
}

caps = rawCapabilities == null ?
new ImmutableCapabilities() :
JSON.toType(rawCapabilities, Capabilities.class);
try {
uri = new URI(rawUri);
} catch (URISyntaxException e) {
Expand Down

0 comments on commit 49f2c2e

Please sign in to comment.