How to run multiple MySQL statements via JDBC sampler in JMeter(如何通过 JMeter 中的 JDBC 采样器运行多个 MySQL 语句)
问题描述
我在 JMeter 2.13 中使用 JDBC 采样器.
我的 JMeter 采样器中有大约 100 个删除语句,如下所示:
delete from abc where id >= ${Variable_Name};从 qwe 中删除其中 id >= ${Variable_Name};从 xyz 中删除其中 id >= ${Variable_Name};
问题是当我在 JDBC 采样器中运行单个语句时,它工作正常.但是当我尝试从我的 JDBC 采样器中运行 2 个或 2 个以上的语句时.它总是抛出错误.
<块引用>您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'delete from qwe where id >= 1;
附近使用的正确语法有人可以提一个解决方法吗?以及我如何克服这个问题.
您似乎无法在单个 JDBC Request
元素中执行多个语句.
我遇到过类似的情况,我需要在继续执行其余测试之前对数据库执行一些清理语句.我能够通过使用嵌套在 Loop Controller
中的 CSV 数据集配置
从外部文件读取 SQL 语句来实现这一点,在一个单独的setUp Thread Group
.
元素是这样放置的:
我使用了以下配置:
循环控制器
- 循环次数:
Forever
CSV 数据集配置
- 文件名:
/path/to/multiple-statements.sql
- 变量名:
STMT
- 在 EOF 上回收:
False
- 在 EOF 上停止线程:
True
JDBC 请求
- 查询:
${STMT}
Loop Controller
设置为永远运行,因为在 CSV 数据集配置
上设置了停止条件.每次迭代都会读取文件的一行,设置变量STMT
,然后JDBC Request
将执行查询${STMT}
.>
当到达文件尾时,setUp Thread Group
将停止,核心测试Thread Group
将继续.
I am using JDBC sampler in JMeter 2.13.
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};
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.
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.
It seems you cannot execute multiple statements in a single JDBC Request
element.
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
.
The elements were placed like this:
And I used the following configurations:
Loop Controller
- Loop Count:
Forever
CSV Data Set Config
- Filename:
/path/to/multiple-statements.sql
- Variable Name:
STMT
- Recycle on EOF:
False
- Stop thread on EOF:
True
JDBC Request
- Query:
${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}
.
When the end-of-file is reached, the setUp Thread Group
will stop and the core test Thread Group
will proceed.
这篇关于如何通过 JMeter 中的 JDBC 采样器运行多个 MySQL 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何通过 JMeter 中的 JDBC 采样器运行多个 MySQL 语句


- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- SQL 临时表问题 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01