当前位置:网站首页>JMeter performance test JDBC request (query database to obtain database data) use "suggestions collection"
JMeter performance test JDBC request (query database to obtain database data) use "suggestions collection"
2022-07-03 02:40:00 【Java architects must see】
JDBC Request
This Sampler You can send a jdbc request (sql sentence ), And get the returned database data for operation . It often needs and JDBC Connection Configuration Configure originals ( Configure database connection related properties , Such as connection name 、 Password etc. ) Use it together .
One 、 preparation
1、 This article USES mysql Database testing , The user name of the database is root( Your own user name ), The user name and password are *********( Your own password )
2、 There are tables in the database :test, The data structure of the table is as follows :
The data in the table is as follows :
select * from tes
3、 Add the required driver jar package
Use different databases , We need to introduce different jar package .
The way 1: Direct will jar Package is copied to the jmeter Of lib Catalog
- mysql database : No need to introduce other database drivers jar package .
- sql server database : download sqljdbc4.jar Put it in jmeter Root directory lib Under the table of contents
- oracle database : take oracle Data installation directory below \product\10.2.0\db_1\jdbc\lib\ojdbc14.jar Put it in jmeter In the root directory lib Under the table of contents
The way 2: adopt Test Plan
If we don't use it, it will jar Copied to the jmeter Of lib The way of cataloguing , We can also use Jmeter Of Test Plan Introduce the corresponding jar package , As follows oracle Data jar package
Two 、 To configure JDBC Connection Configuration
Description of important parameters :
- Variable Name: The name of the database connection pool , We can have multiple jdbc connection configuration, Each can have a different name , stay jdbc request You can use this name to select the appropriate connection pool .
- Database URL: database url,jdbc:mysql:// host ip Or the name of the machine :mysql Port number monitored / Database name , Such as :jdbc:mysql://localhost:3306/test
- JDBC Driver class:JDBC drive
- username: Database login user name
- passwrod: Password of database login
How to fill in different databases , Please refer to the table below :
Datebase | Driver class | Database URL |
|---|---|---|
MySQL | com.mysql.jdbc.Driver | jdbc:mysql://host:port/{dbname} |
PostgreSQL | org.postgresql.Driver | jdbc:postgresql:{dbname} |
Oracle | oracle.jdbc.driver.OracleDriver | jdbc:oracle:thin:user/[email protected]//host:port/service |
Ingres (2006) | ingres.jdbc.IngresDriver | jdbc:ingres://host:port/db[;attr=value] |
MSSQL | com.microsoft.sqlserver.jdbc.SQLServerDriver perhaps net.sourceforge.jtds.jdbc.Driver | jdbc:sqlserver://IP:1433;databaseName=DBname perhaps jdbc:jtds:sqlserver://localhost:1433/"+"library" |
It is roughly as follows :
3、 ... and 、 To configure JDBC Request
Important parameter description :
- Variable Name: The name of the database connection pool , Need and JDBC Connection Configuration Of Variable Name Bound Pool Keep the name the same
- Query: Completed sql Don't add... At the end of the sentence “;”
- Parameter valus: Parameter values
- Parameter types: Parameter type , May refer to :Javadoc for java.sql.Types
- Variable names: preservation sql Statement returns the variable name of the result
- Result variable name: Create an object variable , Save all returned results
- Query timeout: Query timeout
- Handle result set: Define how to handle by callable statements The result returned by the statement
Execution results :
So let's go over here , We've checked the data out of the database as it is , But how to extract the data we need , obviously , If we inquire about sql What is returned is just a data , The above way can already meet our needs , For example, we query the number of records of data ,
select count(*) from test
The result is what we need , Or we can get our content through regular expression .
But if it's like the above , We get multiple lines of data , How do we need to traverse the data , Just get the data we need ? Please see the analysis below .
Four 、JDBC Request A parameterized
Method ( One )、 Defining variables , stay sql query Using variables in :
1、 stay Test Plan Define a variable in ( Of course, you can also use parameterization :Jmeter A parameterized ):
2、sql query Use in ${ Variable name } Method reference of :
select * from test where name='${name}'Method ( Two )、 stay sql query Use in ”?“ As placeholder , And pass the parameter value and parameter type , As shown in the figure below :
1、 The parameter value passed is a constant , As shown in the picture 2 A variable , Multiple variables use ” , “ Separate . Here, if you have data, it's int Type of , Also in Parameter types It's marked as varchar type , Otherwise, it cannot run .
2、 The parameter value passed is a variable , Use ${ Variable name } The way
5、 ... and 、Variables names Parameter usage :
jmeter The explanation given on the official website is : If you set a value for this parameter , It will preserve sql Statement and the total number of data returned . If ,sql Statement returns 2 That's ok ,3 Column , And variables names Set to A,,C, Then the following variables will be set to :
A_#=2 ( Total number of lines ) A_1= The first 1 Column , The first 1 That's ok A_2= The first 1 Column , The first 2 That's ok C_#=2 ( Total number of lines ) C_1= The first 3 Column , The first 1 That's ok C_2= The first 3 Column , The first 2 That's ok
- If the returned result is 0, that A_# and C_# Will be set to 0, Other variables don't set values .
- If you return for the first time 6 Row data , The second time only returns 3 Row data , So the first time there were so many 3 Row data variables are cleared .
- have access to ${A_#}、${A_1}... To get the corresponding value
Example :
We still use the database above , Look up all the data ,test Yes, yes 3 A field ,5 Bar record ( If you forget, you can go back to the first step )
1、 Add one jdbc request be known as ” Parameters 4“, Add one ”Debug Sampler“ Used to view the output results , Set up variables name by column1,column2,column3:
2、 Execution results :
analysis :
column1 Represents all the data in the first column ,column1_# You can get the number of rows in the first column
column1_n: Get the first column n Row data .
column2 and column3 Similar function of , If we only need the first and third columns of data , It can be written. column1,,column3, In the middle of the "," Don't omit .
6、 ... and 、Result variable name Parameter usage :
If you set a value for this parameter , It creates an object variable , Save all returned results , How to get a specific value :columnValue = vars.getObject("resultObject").get(0).get("Column Name")
Execution results :
jmeter Easy to use :http://www.cnblogs.com/0201zcr/p/5046193.html
jmeter Get the returned data as the next request parameter :http://www.cnblogs.com/0201zcr/p/5089620.html
Source file :http://pan.baidu.com/s/1mh3Ag5M
thank : Thank you for reading !
边栏推荐
猜你喜欢

easyExcel

Random shuffle note

How to change the panet layer in yolov5 to bifpn
【ROS进阶篇】第六讲 ROS中的录制与回放(rosbag)

Summary of interview project technology stack
![[principles of multithreading and high concurrency: 1_cpu multi-level cache model]](/img/7e/ad9ea78868126b149bd9f15f587e6c.jpg)
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]

sql server数据库添加 mdf数据库文件,遇到的报错

定了,就选它

Your family must be very poor if you fight like this!

基于线程池的生产者消费者模型(含阻塞队列)
随机推荐
【翻译】具有集中控制平面的现代应用负载平衡
GBase 8c系统表-pg_collation
GBase 8c系统表-pg_attribute
Gbase 8C system table PG_ aggregate
[shutter] setup of shutter development environment (supplement the latest information | the latest installation tutorial on August 25, 2021)
Strategy application of Dameng database
Gbase 8C system table PG_ authid
疫情当头,作为Leader如何进行代码版本和需求开发管控?| 社区征文
[translation] flux is safe. Gain more confidence through fuzzy processing
基于线程池的生产者消费者模型(含阻塞队列)
Add MDF database file to SQL Server database, and the error is reported
【翻译】后台项目加入了CNCF孵化器
Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
Wechat - developed by wechat official account Net core access
How to change the panet layer in yolov5 to bifpn
Javescript 0.1 + 0.2 = = 0.3 problem
My creation anniversary
Cvpr2022 remove rain and fog
GBase 8c 函数/存储过程定义
[fluent] future asynchronous programming (introduction | then method | exception capture | async, await keywords | whencomplete method | timeout method)