如何从JMeter中的JDBC Sampler获取对象结果集

时间:2014-04-09 17:28:47

标签: jmeter jmeter-plugins

我在JMeter中从JDBC Sampler获取结果集对象时遇到问题。 JMeter文档准确地说明了这一点:

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");

所以,我这样配置它就可以了。但是由于上面的文档说我创建了一个"行映射列表",我想我会尝试在BeanShell中创建一个List对象,使其更具可读性。我尝试过这样做,但它没有用。有谁知道答案?

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

错误或多或少是这样的:

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

1 个答案:

答案 0 :(得分:5)

Beanshell不是Java,你需要以不同的方式访问它。

Beanshell不太支持那些“钻石”括号。请修改您的代码如下:

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

上面的代码假定您已在JDBC请求采样器中将resultList设置为“结果变量名称”。

这应该将查询结果打印到 jmeter.log 文件中。

有关Beanshell食谱的详细信息和种类,请参阅How to use BeanShell指南。

相关问题