Oracle database connection settings Jmeter

First, add the required database driver jar package

Embodiment 1: jar packets to be copied directly jmeter lib directory, or lib / ext directory; (pro-test two directories can be used)

 

 

Embodiment 2: Use of the Test Plan is introduced jmeter corresponding jar package; (in fact, this step can be skipped)

 

 

Second, configure JDBC Connection Configuration (emphasis here)

 

 

(1) Variable the Name Bound to Pool
Variable the Name, variable names database connection pool, then JDBC request can be selected by selecting a different connection pool name different database connections, consistent with the JDBC Request the Variable name;
reason: because the link database is the need to configure JDBC Connection configuration in good, and then give the name of a variable, then JDBC Request want to access the database, you have to go through this link configured elements, so we need JDBC Reques by reading the JDBC Connection configuration variables the information; that how to read it, JDBC Reques you need to use a variable, you need to name the mysql elements to apply.

 

(2) Connection Pool Configuration

Max Number of Connections:该数据库连接池的最大连接数,一般可设置为0,意思是每个线程都使用单独的数据库连接,线程之间数据库连接不共享
中文:池中允许的最大连接数。在大多数情况下,将其设置为0,这意味着每个线程将得到它自己的池,其中只有一个连接,即线程之间不共享连接。如果您真的想要使用共享池(为什么?),那么将max count与线程数相同,以确保线程不会相互等待。
Max Wait (ms) 在连接池中取回连接最大等待时间;
如果在试图检索连接过程中(取回连接)超过所设置期限,连接池抛出一个错误;
Time Between Eviction Runs (ms):疏散时间;
在空闲对象驱逐线程运行期间,可以休眠的毫秒数。当非正值时,将运行无空闲对象驱逐器线程。(默认为“60000”,1分钟)(如果当前连接池中某个连接在空闲了time Between Eviction Runs Millis时间后任然没有使用,则被物理性的关闭掉。)
Auto Commit:自动提交sql语句;
打开或关闭连接的自动提交。

 

(3) Connection Validation by Pool
这是Jmeter用来检验数据库连接是否有效的一种机制,超过5秒没有使用的话,就会用validation query去测试下这个连接是否有效

Test While Idle 当空闲的时候测试连接是否断开
中文:测试连接池的空闲连接,验证查询将会被使用去测试。

Soft Min Evictable Idle Time(ms)
中文:最少的时间连接可能在池中闲置,然后才有资格被闲置的对象驱逐出去,额外的条件是至少在池中保持连接。默认值为5000(5秒)

validation Query:验证查询,检验连接是否有效(数据库重启后之前的连接都失效,需要验证查询),这个语句至少是返回一条数据的查询语句。每种数据库都有自己的验证语句。以下是不同数据库对应的验证语句:

 

 

 

(4) Database Connection Configuration
Database URL: jdbc:mysql://服务器地址:3306/数据库名
(比如:jdbc:mysql://ip:3306/数据库名?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true,备注:“&allowMultiQueries=true” 这句话的意思呢 是为了在JDBC中执行多条select语句的时候用的!)
JDBC Driver class:数据库JDBC驱动类名:com.mysql.jdbc.Driver
Username:数据库连接用户名
password:数据库连接密码

 

三、配置JDBC Request

 

 

参数说明:
Variable Name:数据库连接池的名字,需要与上面配置的JDBC Connection Configuration中 Variable Name Bound to Pool的Variable Name相同
Query Type:SQL的类型,查询选择Select Statement;查询SQL需传递参数选择Prepared Select Statement;多个查询语句(不使用参数的情况下)放在一起执行选择Callable statement;
Query:填写的sql语句未尾不要加“;”
Parameter values:若要传递参数入SQL中,可输入相关值或者参数化的变量
Parameter types:参数化对应的数据类型
Variable names:保存sql语句返回结果的变量名(多个时表示第几列)
Result variable name:创建一个对象变量,保存所有返回的结果
Query timeout:查询超时时间
Handle result set:定义如何处理由callable statements语句返回的结果
Variable Name:输入在JDBC Connection Configuration配置的Variable Name的值

 

四、查看结果

添加debug sampler、察看结果树查看查询的结果

 

 

 

 

4.1结果释义:
VEHICLE_ID_#=9 表示VEHICLE_ID列的总行数,VEHICLE_ID_n=xxxxx 表示VEHICLE_ID列的第n行的数据,后续使用${VEHICLE_ID_#}、${VEHICLE_ID_n}进行参数引用;
假如我们只需要第一列和第三列的数据,可以写成column1,column3,中间的","不可以省略;

 

4.2 Result variable name 参数使用方法:
如果给这个参数设置值,它会创建一个对象变量,保存所有返回的结果,然后按照行号加列名去取值,获取具体值的方法:columnValue = vars.getObject(“resultObject”).get(0).get(“Column Name”)

 

 

 

 

 

原文出处:https://blog.csdn.net/weixin_43828011/article/details/101362167

Guess you like

Origin www.cnblogs.com/sucretan2010/p/12021877.html