当前位置:网站首页>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 !
边栏推荐
- javeScript 0.1 + 0.2 == 0.3的问题
- The Linux server needs to install the agent software EPS (agent) database
- Monitoring and management of JVM
- [shutter] banner carousel component (shutter_wiper plug-in | swiper component)
- SQL server queries the table structure of the specified table
- Memory pool (understand the process of new developing space from the perspective of kernel)
- xiaodi-笔记
- A2L file parsing based on CAN bus (2)
- Random shuffle note
- Your family must be very poor if you fight like this!
猜你喜欢
[shutter] setup of shutter development environment (supplement the latest information | the latest installation tutorial on August 25, 2021)
Your family must be very poor if you fight like this!
Pytorch convolution network regularization dropblock
Restcloud ETL cross database data aggregation operation
xiaodi-笔记
Tongda OA homepage portal workbench
[fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)
Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
Today, it's time to copy the bottom!
基于can总线的A2L文件解析(2)
随机推荐
leetcode540
Informatics Olympiad one general question bank 1006 a+b questions
GBase 8c系统表-pg_auth_members
Gbase 8C create user / role example 2
[fluent] futurebuilder asynchronous programming (futurebuilder construction method | asyncsnapshot asynchronous calculation)
[fluent] future asynchronous programming (introduction | then method | exception capture | async, await keywords | whencomplete method | timeout method)
sql server数据库添加 mdf数据库文件,遇到的报错
Two dimensional format array format index subscript continuity problem leads to return JSON format problem
为什么会选择框架?选择什么样的框架
Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
Monitoring and management of JVM
GBase 8c 函数/存储过程定义
What is the way out for children from poor families?
2022-2028 global splicing display industry research and trend analysis report
[Hcia]No.15 Vlan间通信
Detailed analysis of micro service component sentinel (hystrix)
Gbase 8C system table PG_ amop
GBase 8c系统表-pg_am
Why choose a frame? What frame to choose
Summary of interview project technology stack