本文介绍了如何从 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 请求采样器中将 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 指南了解更多详情和一种豆壳食谱.

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

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

06-19 06:42