Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDBCSampler discards ResultSet from a PreparedStatement. #2418

Closed
asfimport opened this issue Oct 28, 2010 · 3 comments
Closed

JDBCSampler discards ResultSet from a PreparedStatement. #2418

asfimport opened this issue Oct 28, 2010 · 3 comments

Comments

@asfimport
Copy link
Collaborator

whitingjr (Bug 50173):
Hi,
I am using JMeter with a Test Plan that uses a JDBC Request with a PreparedStatement query type.
When running this I am getting the following error in the jmeter.log file

2010/10/28 11:30:31 INFO - jmeter.threads.JMeterThread: Thread started: JDBC Users 1-1
2010/10/28 12:13:38 ERROR - jmeter.threads.JMeterThread: Error while processing sampler 'PREPARED SELECT Customer JDBC Request' : java.lang.NullPointerException
at org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler.getStringFromResultSet(JDBCSampler.java:415)
at org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler.resultSetsToString(JDBCSampler.java:268)
at org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler.sample(JDBCSampler.java:208)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:348)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:243)
at java.lang.Thread.run(Thread.java:619)

The query (below) can be expected to return a number of records
SELECT * FROM Customer WHERE ID=?;
the param is set to 1

If I use instead a SelectStatement results are returned so the query itself is not at fault.

I have retrieved the code for the v2_4 tag to identify the root cause for the NPE and create a patch. This bug report includes a patch against trunk as the issue is also in trunk.
The root cause is due to:
org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler.sample(Entry e)

The code path for PreparedStatements types starting on line 204 has in it a call to
org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate()
which returns a ResultSet. The side effect of the call is to set the JDBCPreparedStatement.currentResultSet field member to null.
JDBCSampler does not keep the ResultSet reference. Instead it is discarded.

The call on the next line (208)
String sb = resultSetsToString(pstmt,true,null)
again tries to get the ResultSet on line 267. This causes a NullPointerException because the JDBCPreparedStatement.currentResultSet field was set to null earlier.

Looking at the code path for a CALLABLE statement type (line 190) shows better handling for queries that return ResultSet.

The two lines
207,208

replaced with
boolean hasResultSet = pstmt.execute();
String sb = resultSetsToString(pstmt,hasResultSet,null);

fixes the defect.

Regards,
Jeremy Whiting
Red Hat

Severity: normal
OS: All

@asfimport
Copy link
Collaborator Author

whitingjr (migrated from Bugzilla):
Attempted to run the Ant test target but this failed.

BUILD FAILED
JMeter-trunk/build.xml:1723: <fixcrlf> error: srcdir does not exist: 'JMeter-trunk/bin/testfiles'

Created attachment JMeter-50173.patch: File with SVN diff patch details.

JMeter-50173.patch
### Eclipse Workspace Patch 1.0
#P JMeter-trunk
Index: src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java
===================================================================
--- src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java	(revision 1028280)
+++ src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java	(working copy)
@@ -204,8 +204,8 @@
             } else if (PREPARED_SELECT.equals(_queryType)) {
                 PreparedStatement pstmt = getPreparedStatement(conn);
                 setArguments(pstmt);
-                pstmt.executeQuery();
-                String sb = resultSetsToString(pstmt,true,null);
+                boolean hasResultSet = pstmt.execute();
+                String sb = resultSetsToString(pstmt,hasResultSet,null);
                 res.setResponseData(sb.getBytes(ENCODING));
             } else if (PREPARED_UPDATE.equals(_queryType)) {
                 PreparedStatement pstmt = getPreparedStatement(conn);

@asfimport
Copy link
Collaborator Author

Sebb (migrated from Bugzilla):
(In reply to comment 1)

Attempted to run the Ant test target but this failed.

BUILD FAILED
JMeter-trunk/build.xml:1723: <fixcrlf> error: srcdir does not exist:
'JMeter-trunk/bin/testfiles'

In that case, you have not downloaded the full source.

@asfimport
Copy link
Collaborator Author

Sebb (migrated from Bugzilla):
Thanks for the patch, applied to SVN:

URL: http://svn.apache.org/viewvc?rev=1028518&view=rev
Log:
#2418 - JDBCSampler discards ResultSet from a PreparedStatement

Modified:
jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java
jakarta/jmeter/trunk/xdocs/changes.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant