Skip to content

Commit

Permalink
fix: Prevent resource leak by closing the PreparedStatement (#390)
Browse files Browse the repository at this point in the history
Co-authored-by: BURJA Lucian <[email protected]>
  • Loading branch information
lburja and BURJA Lucian authored Oct 8, 2024
1 parent 54aa50c commit 504c457
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,21 @@ public Output run(RunContext runContext) throws Exception {
})
.buffer(this.chunk, this.chunk)
.map(throwFunction(o -> {
PreparedStatement ps = connection.prepareStatement(sql);
ParameterType parameterMetaData = ParameterType.of(ps.getParameterMetaData());
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ParameterType parameterMetaData = ParameterType.of(ps.getParameterMetaData());

for (Object value : o) {
ps = this.addRows(ps, parameterMetaData, value, cellConverter, connection);
for (Object value : o) {
this.addRows(ps, parameterMetaData, value, cellConverter, connection);

ps.addBatch();
ps.clearParameters();
}
ps.addBatch();
ps.clearParameters();
}

int[] updatedRows = ps.executeBatch();
connection.commit();
int[] updatedRows = ps.executeBatch();
connection.commit();

return Arrays.stream(updatedRows).sum();
return Arrays.stream(updatedRows).sum();
}
}));

Integer updated = flowable
Expand Down

0 comments on commit 504c457

Please sign in to comment.