[Turn] Jmeter of JDBC Request and parametric


JDBC Request
 
  This jdbc Sampler can send a request (sql statement) to the database, and acquires the returned data database operation. It often requires an original configuration and JDBC Connection Configuration (configuration-related database connection properties, such as connection name, password, etc.) used together.
 

 

First, the preparatory work

  1. As used herein, the mysql database
  2. There are tables in the database
  3. Adding driver jar package

Use a different database, we need to introduce a different jar package.
Method 1: Copy the jar packets directly to the lib directory jmeter
mysql database: jar without introducing other database-driven package.
sql server database: downloading into jmeter sqljdbc4.jar root lib directory
oracle database: oracle installation directory data following \ product \ 10.2.0 \ db_1 \ jdbc \ lib \ ojdbc14.jar into the root directory jmeter lib directory
 
embodiment 2: the Test Plan
if we do not use the copy of the jar to the embodiment jmeter lib directory, we can also use the Test Plan introduced jmeter corresponding jar package, as will the introduction of the jar package database mysql

 

Second, configure JDBC Connection Configuration


 
Important Parameters

  • Variable Name: name of the database connection pool, we can have multiple jdbc connection configuration, each of which can play a different name, you can use to select the appropriate connection pool by this name in jdbc request.
  • Database URL: database url, jdbc: mysql: // host machine name or ip: mysql listening port number / name of the database, such as: jdbc: mysql: // localhost: 3306 / test
  • JDBC Driver class: JDBC Driver
  • username: database login user name
  • passwrod: database login password

 
Different databases to fill specific way, you can refer to the following table:

Database 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/pass@//host:port/service
Ingres (2006) ingres.jdbc.IngresDriver jdbc:ingres://host:port/db[;attr=value]
MSSQL com.microsoft.sqlserver.jdbc.SQLServerDriver或者net.sourceforge.jtds.jdbc.Driver jdbc:sqlserver://IP:1433;databaseName=DBname或者jdbc:jtds:sqlserver://localhost:1433/"+"library"

Third, configure JDBC Request

 
Important parameters:
 

  • Variable Name: the name of the database connection pool, need to be consistent with the JDBC Connection Configuration of Variable Name Bound Pool name
  • Query: Fill sql statement
  • Parameter valus: Parameter Value
  • Parameter types: Type parameter, refer to: Javadoc for java.sql.Types
  • Variable names: save sql statement returns the result variable name
  • Result variable name: create an object variable, save all results returned
  • Query timeout: query timeout
  • Handle result set: how to define the results are returned by the callable statements statements
     

Perform here, we have to check the data from the database as it came out, but the specifics of how the data we need to remove it, obviously, if we sql query returns only one data, the above approach has to meet our needs , as we record the number of query data
 
select count(*) from test
 
content check out the results that we need, or by regular expressions can get access to our content.
 
But if it looks like the above, we get out of the multiple rows of data, how we need to traverse the data, only the data we need to get out of it? See the following analysis.

Four, JDBC Request parametric

The method, the Jmeter parameterization, the use of variables in sql query

  1. Jmeter parameterization, you can refer to my previous article
  2. sql query using the variable name} {$ reference

The second method used in the SQL Query "?" As placeholders and passing parameters and parameter types
 

  1. Is a constant parameter values ​​passed, a plurality of variables "," separator

     
  2. Is a variable parameter values ​​are passed, using the variable name} {$ manner

 

Five, Variables names parameter to use

jmeter official website for explanation is: If this parameter is set to a value that will save the data returned by the sql statement and return the number of rows of data. If, sql statement returns two rows and three columns, and the variables names set to A ,, C, then the following variables are set to:
 
  A _ # = 2 (total number of lines)
  A_1 = column 1, line 1
  A_2 = 1 column, line 2
  C _ # = 2 (number of rows)
  C_l = 3, lines. 1
  C_2 = column 3, line 2
 

  • If the return result is 0, then A_ # and C_ # will be set to 0, the value of other variables will not be set.
  • If the first 6 rows of data returned, second only return 3 rows of data, then the first time that more than 3 rows of data variables will be cleared.
  • Can $ {A _ #}, $ {A_1} ... obtain the corresponding value of
     

Examples
add a "Debug Sampler" to view the result output is provided as variables name column1, column2, column3:

 
Results of the

 
Resolution:

  • Column1 representative of all the data in the first column, column1_ # may acquire the number of rows in the first column
     
  • column1_n: obtaining data of the n rows of the first column.
     
  • Similar features column3 column2 and, if we only the first and third columns of data needs to be written column1,, column3, intermediate, "and" can not be omitted.
     

Six, Result variable name parameter method

If this parameter is set to a value, it will create an object variable (list type), to save all the results returned, the value of specific acquisition method:. ColumnValue = vars.getObject ( "resultObject") get (0) .get ( "Column Name ")
 

 
Results of the

 

Guess you like

Origin www.cnblogs.com/crystal1126/p/12545734.html