This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.14.x by this push:
new 0d41912 CAMEL-17599: camel-jdbc - ensure Statement is closed to not
leak.
0d41912 is described below
commit 0d41912531f7bbe259cb47b00caeb17c200eb71e
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Feb 5 09:35:58 2022 +0100
CAMEL-17599: camel-jdbc - ensure Statement is closed to not leak.
---
.../java/org/apache/camel/component/jdbc/JdbcProducer.java | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git
a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
index 4effe05..1b9d189 100644
---
a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
+++
b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
@@ -35,6 +35,7 @@ import org.apache.camel.ExtendedExchange;
import org.apache.camel.spi.Synchronization;
import org.apache.camel.support.DefaultProducer;
import org.apache.camel.support.PropertyBindingSupport;
+import org.apache.camel.support.SynchronizationAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -198,7 +199,14 @@ public class JdbcProducer extends DefaultProducer {
try {
// We might need to leave it open to allow post-processing of the
result set. This is why we
// are not using try-with-resources here.
- Statement stmt = conn.createStatement();
+ final Statement stmt = conn.createStatement();
+ // ensure statement is closed (to not leak) when exchange is done
+ exchange.adapt(ExtendedExchange.class).addOnCompletion(new
SynchronizationAdapter() {
+ @Override
+ public void onDone(Exchange exchange) {
+ closeQuietly(stmt);
+ }
+ });
if (parameters != null && !parameters.isEmpty()) {
Map<String, Object> copy = new HashMap<>(parameters);