This is an automated email from the ASF dual-hosted git repository.

nnag pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new d4b7c14  GEODE-7864: Closing the query statements after execution. 
(#4873)
d4b7c14 is described below

commit d4b7c1459c10ed1934080ef4a398b9d6232cfb45
Author: Nabarun Nag <[email protected]>
AuthorDate: Mon Apr 6 15:17:26 2020 -0700

    GEODE-7864: Closing the query statements after execution. (#4873)
---
 .../java/org/apache/geode/internal/jta/CacheUtils.java   | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git 
a/geode-junit/src/main/java/org/apache/geode/internal/jta/CacheUtils.java 
b/geode-junit/src/main/java/org/apache/geode/internal/jta/CacheUtils.java
index 530ca78..2ce567e 100644
--- a/geode-junit/src/main/java/org/apache/geode/internal/jta/CacheUtils.java
+++ b/geode-junit/src/main/java/org/apache/geode/internal/jta/CacheUtils.java
@@ -144,12 +144,13 @@ public class CacheUtils {
     String sql = "select * from " + tableName;
 
     Connection conn = ds.getConnection();
-    Statement sm = conn.createStatement();
-    ResultSet rs = sm.executeQuery(sql);
-    while (rs.next()) {
-      System.out.println("id " + rs.getString(1) + " name " + rs.getString(2));
+    try (Statement sm = conn.createStatement()) {
+      ResultSet rs = sm.executeQuery(sql);
+      while (rs.next()) {
+        System.out.println("id " + rs.getString(1) + " name " + 
rs.getString(2));
+      }
+      rs.close();
     }
-    rs.close();
     conn.close();
   }
 
@@ -159,8 +160,9 @@ public class CacheUtils {
     Connection conn = ds.getConnection();
     // System.out.println (" trying to drop table: " + tableName);
     String sql = "drop table " + tableName;
-    Statement sm = conn.createStatement();
-    sm.execute(sql);
+    try (Statement sm = conn.createStatement()) {
+      sm.execute(sql);
+    }
     conn.close();
   }
 

Reply via email to