如何在JMeter Beanshell中从JDBC采样器获取对象结果集

如何在JMeter Beanshell中从JDBC采样器获取对象结果集,jmeter,jmeter-plugins,Jmeter,Jmeter Plugins,从JMeter中的JDBC采样器获取结果集对象时遇到问题。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: col

从JMeter中的JDBC采样器获取结果集对象时遇到问题。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");
List 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")
jmeter.util.BeanShellInterpreter:调用bsh时出错
方法:在文件中求值:内联求值:
``列表结果=vars.getObject(“结果列表”)

Beanshell不是Java,您需要以稍微不同的方式访问它

Beanshell并不十分支持这些“菱形”括号。请修改您的代码如下:

ArrayList result = vars.getObject("resultList");
for (HashMap table : result) {
    for (Object column : table.keySet()) {
        log.info(column + "=" + table.get(column));
    }
}
上面的代码假设您已将
resultList
设置为JDBC请求采样器中的“结果变量名”

将查询结果打印到jmeter.log文件中


请参阅指南了解更多详细信息和Beanshell菜谱。

是的,这确实非常有效。非常感谢。