当前位置:网站首页>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 !
边栏推荐
猜你喜欢
sql server数据库添加 mdf数据库文件,遇到的报错
Add automatic model generation function to hade
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
错误Invalid bound statement (not found): com.ruoyi.stock.mapper.StockDetailMapper.xxxx解决
Can netstat still play like this?
Tongda OA V12 process center
Mathematical statistics -- Sampling and sampling distribution
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
oauth2.0鉴权,登录访问 “/oauth/token”,请求头Authorization(basicToken)如何取值???
Principle and application of database
随机推荐
内存池(内核角度理解new开辟空间的过程)
Xiaodi notes
awk从入门到入土(2)认识awk内置变量和变量的使用
sql server 查詢指定錶的錶結構
定了,就选它
Pytest (6) -fixture (Firmware)
5. File operation
Producer consumer model based on thread pool (including blocking queue)
二维格式数组格式索引下标连续问题导致 返回json 格式问题
The Linux server needs to install the agent software EPS (agent) database
UDP receive queue and multiple initialization test
Basic operation of binary tree (C language version)
Current situation and future of Web3 in various countries
面试八股文整理版
Javescript 0.1 + 0.2 = = 0.3 problem
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
Two dimensional format array format index subscript continuity problem leads to return JSON format problem
Gbase 8C trigger (I)
Apple releases MacOS 11.6.4 update: mainly security fixes
GBase 8c系统表pg_database