Skip to content

Commit 1462157

Browse files
authored
[SQL Server] Close attributes
Added code to close the ResultSet, Statement and release connection from datasource
1 parent de0d41a commit 1462157

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

spring-content-jpa/src/main/java/internal/org/springframework/content/jpa/io/SQLServerBlobResource.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,17 @@ public InputStream getInputStream() throws IOException {
5353
}
5454
rs = stmt.executeQuery(sql);
5555

56-
if (!rs.next())
57-
return null;
56+
if (!rs.next()) {
57+
try {
58+
rs.close();
59+
stmt.close();
60+
DataSourceUtils.releaseConnection(conn, ds);
61+
return null;
62+
} catch (SQLException sqle) {
63+
log.debug("Failed to release database connection while fetching content ->", sqle);
64+
log.error("failed to release database connection while fetching content {}", id, sqle);
65+
}
66+
}
5867
is = rs.getBinaryStream(2);
5968
}
6069
catch (SQLException e) {

0 commit comments

Comments
 (0)