You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2020/09/08 11:10:29 UTC
[camel-kafka-connector] branch master updated: Fix potentially
unreleased DB resources in test code
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector.git
The following commit(s) were added to refs/heads/master by this push:
new a7bcd9c Fix potentially unreleased DB resources in test code
a7bcd9c is described below
commit a7bcd9c0f4765112e997e3fcfd6d72df829a92dd
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Tue Sep 8 12:35:14 2020 +0200
Fix potentially unreleased DB resources in test code
---
.../camel/kafkaconnector/jdbc/client/DatabaseClient.java | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/client/DatabaseClient.java b/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/client/DatabaseClient.java
index 6f2f452..855fcdc 100644
--- a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/client/DatabaseClient.java
+++ b/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/client/DatabaseClient.java
@@ -42,20 +42,21 @@ public class DatabaseClient {
}
public void runQuery(String query, Consumer<ResultSet> consumer) throws SQLException {
- ResultSet rs = connection.prepareStatement(query).executeQuery();
+ try (ResultSet rs = connection.prepareStatement(query).executeQuery()) {
- while (rs.next()) {
- consumer.accept(rs);
+ while (rs.next()) {
+ consumer.accept(rs);
+ }
}
}
public int count(String table) throws SQLException {
String query = String.format("select count(*) as count from %s", table);
- ResultSet rs = connection.prepareStatement(query).executeQuery();
-
- while (rs.next()) {
- return rs.getInt("count");
+ try (ResultSet rs = connection.prepareStatement(query).executeQuery()) {
+ while (rs.next()) {
+ return rs.getInt("count");
+ }
}
return 0;