Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: result set leak #72

Merged
merged 1 commit into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/main/java/ca/bc/gov/nrs/api/service/QueryExecutorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,22 @@ public List<Map<String, Object>> executeQuery(String query) throws SQLException
try (var connection = dataSource.getConnection()) {
connection.setReadOnly(true);
try (var statement = connection.prepareStatement(query)) {
var result = statement.executeQuery();
var metaData = result.getMetaData();
List<String> columnNames = new ArrayList<>();
for (int i = 1; i <= metaData.getColumnCount(); i++) {
String columnName = metaData.getColumnName(i);
columnNames.add(columnName);
}
while (result.next()) {
Map<String, Object> row = new HashMap<>();
for (int i = 0; i < metaData.getColumnCount(); i++) {
String columnName = columnNames.get(i);
Object columnValue = result.getObject(i + 1);
row.put(columnName, columnValue);
try(var result = statement.executeQuery()){
var metaData = result.getMetaData();
List<String> columnNames = new ArrayList<>();
for (int i = 1; i <= metaData.getColumnCount(); i++) {
String columnName = metaData.getColumnName(i);
columnNames.add(columnName);
}
while (result.next()) {
Map<String, Object> row = new HashMap<>();
for (int i = 0; i < metaData.getColumnCount(); i++) {
String columnName = columnNames.get(i);
Object columnValue = result.getObject(i + 1);
row.put(columnName, columnValue);
}
results.add(row);
}
results.add(row);
}
}
} catch (Exception e) {
Expand Down