You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2016/09/10 16:16:01 UTC

svn commit: r1760194 - /jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java

Author: fschumacher
Date: Sat Sep 10 16:16:01 2016
New Revision: 1760194

URL: http://svn.apache.org/viewvc?rev=1760194&view=rev
Log:
Followup to r1759668. Close PreparedStatements as they are no longer cached and reused.

Bugzilla Id: 60085

Modified:
    jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java

Modified: jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java?rev=1760194&r1=1760193&r2=1760194&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java (original)
+++ jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java Sat Sep 10 16:16:01 2016
@@ -173,14 +173,15 @@ public abstract class AbstractJDBCTestEl
                     close(rs);
                 }
             } else if (CALLABLE.equals(_queryType)) {
-                CallableStatement cstmt = getCallableStatement(conn);
-                int[] out = setArguments(cstmt);
-                // A CallableStatement can return more than 1 ResultSets
-                // plus a number of update counts.
-                boolean hasResultSet = cstmt.execute();
-                sample.latencyEnd();
-                String sb = resultSetsToString(cstmt,hasResultSet, out);
-                return sb.getBytes(ENCODING);
+                try (CallableStatement cstmt = getCallableStatement(conn)) {
+                    int[] out = setArguments(cstmt);
+                    // A CallableStatement can return more than 1 ResultSets
+                    // plus a number of update counts.
+                    boolean hasResultSet = cstmt.execute();
+                    sample.latencyEnd();
+                    String sb = resultSetsToString(cstmt,hasResultSet, out);
+                    return sb.getBytes(ENCODING);
+                }
             } else if (UPDATE.equals(_queryType)) {
                 stmt = conn.createStatement();
                 stmt.setQueryTimeout(getIntegerQueryTimeout());
@@ -190,23 +191,25 @@ public abstract class AbstractJDBCTestEl
                 String results = updateCount + " updates";
                 return results.getBytes(ENCODING);
             } else if (PREPARED_SELECT.equals(_queryType)) {
-                PreparedStatement pstmt = getPreparedStatement(conn);
-                setArguments(pstmt);
-                ResultSet rs = null;
-                try {
-                    rs = pstmt.executeQuery();
-                    sample.latencyEnd();
-                    return getStringFromResultSet(rs).getBytes(ENCODING);
-                } finally {
-                    close(rs);
+                try (PreparedStatement pstmt = getPreparedStatement(conn)) {
+                    setArguments(pstmt);
+                    ResultSet rs = null;
+                    try {
+                        rs = pstmt.executeQuery();
+                        sample.latencyEnd();
+                        return getStringFromResultSet(rs).getBytes(ENCODING);
+                    } finally {
+                        close(rs);
+                    }
                 }
             } else if (PREPARED_UPDATE.equals(_queryType)) {
-                PreparedStatement pstmt = getPreparedStatement(conn);
-                setArguments(pstmt);
-                pstmt.executeUpdate();
-                sample.latencyEnd();
-                String sb = resultSetsToString(pstmt,false,null);
-                return sb.getBytes(ENCODING);
+                try (PreparedStatement pstmt = getPreparedStatement(conn)) {
+                    setArguments(pstmt);
+                    pstmt.executeUpdate();
+                    sample.latencyEnd();
+                    String sb = resultSetsToString(pstmt,false,null);
+                    return sb.getBytes(ENCODING);
+                }
             } else if (ROLLBACK.equals(_queryType)){
                 conn.rollback();
                 sample.latencyEnd();