(3), Jmeter connection MySQL configuration (can execute multiple sql statements)

Note: mysqlconnector/j 3.1.1 or later versions only support the execution of multiple sql statements

1. Download the jdbc driver

In order to connect to the Mysql database, you also need a jdbc driver: mysql-connector-java-5.1.41-bin.jar

CSDN download address: https://download.csdn.net/download/glongljl/10398325

2. Add jdbc driver

 Open JMeter, click on the test plan, click the "Browse..." button, and add your JDBC driver.

3. Add jdbc connection configuration

Add a thread group, right-click on "Thread Group", and add a "JDBC Connection Configuration" below

Let's configure the JDBCConnection Configuration page.

 

Database URL is the connection string of MySQL. If you want to execute multiple SQL statements, add "?allowMultiQueries=true" later

JDBC Driver Class is the native jdbc driver path. Mysql database, default com.mysql.jdbc.Driver, different databases have different default values

4. Add a JDBC Request

Right click on "Thread Group" and add a "JDBCrequest" below

Let's configure the JDBC request page

If you want to execute multiple SQL statements, the Quer Type must select Callable statement. When using Callablestatement , you can include multiple SQLs at a time , as shown in the figure above.

It should be noted here that VariableName Bound to Pool is consistent with JDBC CONNECTION

Variable Name : The name of         the database connection pool, which needs to be consistent with the Variable Name Bound Pool name of the JDBC Connection Configuration

·         Query : Do not add ";" to the end of the filled SQL statement

Parameter values :         parameter values

Parameter types : parameter types, please refer to: Javadoc         for java.sql.Types

Variable names : save the variable name of the result returned by         the sql statement

Result variable name : Create an object variable to hold all returned results        

Query timeout :         query timeout time

Handle result set : defines how to handle the         results returned by callable statements

Note: Variables names parameter usage method:

  The explanation given by Jmeter's official website is: if a value is set for this parameter, it will save the data returned by the sql statement and the total number of rows of the returned data. If the sql statement returns 2 rows, 3 columns, and the variable names are set to A,,C, then the following variables will be set to:

  A_#=2 (total rows)

  A_1=column 1, row 1

  A_2=column 1, row 2

  C_#=2 (total number of rows)

  C_1=column 3, row 1

  C_2=column 3, row 2

If the return result is 0, then A_# and C_# will be set to 0, and other variables will not be set.

If 6 rows of data are returned for the first time, and only 3 rows of data are returned the second time, then the extra 3 rows of data variables will be cleared for the first time.

You can use ${A_#}, ${A_1}... to get the corresponding value

1. Set the variable to save the result returned by sql

2. To call the variable method, add "_1" or the like after the original variable

 

 

5. Add assertions

Right click on Thread Group---->Add--->Assertions---->Response Assertion.

6. Add a view result tree

Right click on Thread Group---->Add--->Listener---->View Results Tree.

Start, check the result tree to see if the operation is successful



7. Common mistakes

1. JDBC Request报Error preloading the connection pool错误


Reason: jdbcconnection configuration maximum connection data is too large


Modify it to 10 and the problem is solved




     


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325973552&siteId=291194637