本文介绍了如何从JMeter Beanshell中的JDBC Sampler获取对象结果集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从JMeter的JDBC Sampler获取结果集对象. JMeter文档完全说明了这一点:

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

因此,我像这样配置了它,并且可以正常工作.但是由于上面的文档说我创建了一个行映射列表",所以我想我会尝试在BeanShell中从中创建一个List对象,以使其更具可读性.我尝试这样做,但是没有用.有人知道答案吗?

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

推荐答案

Beanshell不是Java,您需要对其进行一些不同的访问.

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

Beanshell不太支持那些钻石"括号.请按如下所示修改您的代码:

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

上面的代码假定您已在JDBC Request Sampler中将resultList设置为结果变量名称".

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

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

That should print query result into jmeter.log file.

有关更多详细信息,请参见如何使用BeanShell 指南.一种Beanshell食谱.

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

这篇关于如何从JMeter Beanshell中的JDBC Sampler获取对象结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-19 06:42