如何在JMeter中通过JDBC采样器运行多个MySQL语句 [英] How to run multiple MySQL statements via JDBC sampler in JMeter
问题描述
我正在JMeter 2.13中使用JDBC采样器.
I am using JDBC sampler in JMeter 2.13.
我的JMeter采样器中大约有100条delete语句,如下所示:
I have around 100 delete statements in my JMeter sampler like below:
delete from abc where id >= ${Variable_Name};
delete from qwe where id >= ${Variable_Name};
delete from xyz where id >= ${Variable_Name};
问题是,当我在JDBC采样器中运行单个语句时,它可以正常工作.但是,无论何时我尝试从我的JDBC采样器中运行2条或2条以上的语句.它总是抛出错误.
Problem is that when I run a single statement in JDBC sampler, it works fine. But when ever I try to run 2 or more than 2 statements from my JDBC sampler. It always throws error.
您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册以获取正确的语法,以在'从qwe那里删除,其中id> = 1;
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delete from qwe where id >= 1;
有人可以提及解决方法吗?以及如何克服这个问题.
Can someone please mention a workaround it? and how I can overcome this problem.
推荐答案
似乎您不能在单个 JDBC Request
元素中执行多个语句.
It seems you cannot execute multiple statements in a single JDBC Request
element.
我遇到类似的情况,在继续进行其余测试之前,我需要在数据库上执行一些清理语句.我可以通过使用 CSV Data Set Config
嵌套在 Loop Controller
中的单独的 setUp Thread Group
中的外部文件中读取SQL语句来实现此目的. .
I had a similar situation where I needed to execute some clean up statements on the database before proceeding with the rest of the tests. I was able to achieve this by reading the SQL statements from an external file, using CSV Data Set Config
nested in a Loop Controller
, in a separate setUp Thread Group
.
元素放置如下:
我使用了以下配置:
回路控制器
- 循环数:
Forever
CSV数据集配置
- 文件名:
/path/to/multiple-statements.sql
- 变量名称:
STMT
- 在EOF上回收:
False
- 在EOF上停止线程:
True
- Filename:
/path/to/multiple-statements.sql
- Variable Name:
STMT
- Recycle on EOF:
False
- Stop thread on EOF:
True
JDBC请求
- 查询:
${STMT}
Loop Controller
设置为永久运行,因为在CSV Data Set Config
上设置了停止条件.每次迭代将读取文件的一行,设置变量STMT
,然后JDBC Request
将执行查询${STMT}
.
The Loop Controller
is set to run forever, as the stop condition is set on the CSV Data Set Config
. Each iteration will read one line of the file, set the variable STMT
, then JDBC Request
will execute the query ${STMT}
.
到达文件末尾时,setUp Thread Group
将停止,并且核心测试Thread Group
将继续进行.
When the end-of-file is reached, the setUp Thread Group
will stop and the core test Thread Group
will proceed.
这篇关于如何在JMeter中通过JDBC采样器运行多个MySQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!