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 语句
基础教程推荐
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
