How to get object result set from JDBC Sampler in JMeter Beanshell

djangofan picture djangofan · Apr 9, 2014 · Viewed 7.8k times · Source

I am having trouble getting the result set object from JDBC Sampler in JMeter. The JMeter documentation says this exactly:

Result Variable Name
If specified, this will create an Object variable containing a list of
    row maps. Each map contains the column name as the key and the column 
    data as the value. 
Usage:
  columnValue = vars.getObject("resultObject").get(0).get("Column Name");

So, I configured it like that and it works. But since the document above says that I creates a "list of row maps", I thought I would try to create a List object from it in BeanShell to make it more readable. I tried doing this but it didn't work. Does anyone know the answer?

List<Map<String,Integer>> results = vars.getObject("resultList");

And the error is more or less something like this:

jmeter.util.BeanShellInterpreter: Error invoking bsh 
 method: eval   In file: inline evaluation of:
 ``List<Map<String,Integer>> results = vars.getObject("resultList")

Answer

Dmitri T picture Dmitri T · Apr 10, 2014

Beanshell is not Java, you need to access it a little bit differently.

Those "diamond" brackets are not very supported by Beanshell. Please amend your code as follows:

ArrayList result = vars.getObject("resultList");
for (HashMap table : result) {
    for (Object column : table.keySet()) {
        log.info(column + "=" + table.get(column));
    }
}

The code above assumes that you have set resultList as a "Result Variable Name" in your JDBC Request Sampler.

That should print query result into jmeter.log file.

See How to use BeanShell guide for more details and kind of Beanshell cookbook.