jmeter jdbc request使用详解

1、在使用 jdbc request之前需要加载一个jar包

在test plan中将jar包引入到classpath中

 

 

2、创建一个JDBC Connection Configuration

  

Variable Name: 变量名称,需要变量名绑定到池。需要唯一标识。与JDBC取样器中的相对应,决定JDBC取样的配置。简单理解就是在JDBC request的时候确定去哪个绑定的配置。

MaxNumber of Connection: 数据库最大链接数

PoolTimeout: 数据库链接超时,单位ms

Idle Cleanup Interval (ms): 数据库空闲清理的间隔时间,单位ms

Auto Commit:自动提交。有三个选项,true、false、编辑(自己通过jmeter提供的函数设置)

Transaction Isolation:   

事务间隔级别设置,主要有如下几个选项:(对JMX加解密) 

TRANSACTION_REPEATABLE_READ事务重复读、TRANSACTION_READ_COMMITTED事务已提交读 、TRANSACTION_SERIALIZABLE事务序列化 、TRANSACTION_READ_UNCOMMITTED事务未提交读、TRANSACTION_NODE  事务节点 、DEFAULT默认、编辑

Keep-Alive: 是否保持连接

Max  Connection age (ms):最大连接时长,超过时长的会被拒绝

Validation Query:验证查询,检验连接是否有效(数据库重启后之前的连接都失效,需要验证查询)

Database URL:如jdbc:mysql://localhost:3306/test

表示本地数据库,3306端口,数据库名称为test

JDBCDriver Class: JDBC的类,如org.gjt.mm.mysql.Driver  

 

3、创建  sampler - >jdbc request  

 

variable 需要填写的内容与前面的 variable name bound to pool 的内容一致 

Query Type- Set this according to the statement type: 
• Select Statement
• Update Statement - use this for Inserts and Deletes as well
• Callable Statement
• Prepared Select Statement
• Prepared Update Statement - use this for Inserts and Deletes as well
• Commit
• Rollback
• Autocommit(false)
• Autocommit(true)
• Edit - this should be a variable reference that evaluates to one of the above

Parameter values : 参数

Parameter types- Comma-separated list of SQL parameter types (e.g. INTEGER, DATE, VARCHAR, DOUBLE)

Variable Names- Comma-separated list of variable names to hold values returned by Select statements, Prepared Select Statements or CallableStatement. Note that when used with CallableStatement, list of variables must be in the same sequence as the OUT parameters returned by the call. If there are less variable names than OUT parameters only as many results shall be stored in the thread-context variables as variable names were supplied. If more variable names than OUT parameters exist, the additional variables will be ignored.

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

 

如果使用了select 结果有多条记录,需要对其中的某个结果进行操作:

将结果存储在result中,result是以一个map形式进行的存储,需要对其中的某个数据进行操作的时候,可以在后面使用beanshellprocessor 

上面的columnvalue就存储了某些数据,可以作为变量进行使用  如:${columnValue}

 http://www.cnblogs.com/yingchen/p/5124838.html

第二种方法使用:

A,B,C对应的是上面sql查出来的三个字段

使用方法,在其他地方使用  ${A_#},${A_1},${A_2}分别表示,行数, 第一列,第一行,第一列第二行。

 

posted on   yingchen  阅读(883)  评论(0编辑  收藏  举报

编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示