Go: How to use JDBC request

Source: Internet
Author: User

1. Download the mysql jar package

Download MySQL jar package

http://dev.mysql.com/downloads/connector/j/

NET Disk: Mysql-connector-java-commercial-5.1.25-bin.jar

To view the supported MySQL versions of the jar package:

Http://dev.mysql.com/doc/connector-j/en/connector-j-versions.html

View MySQL database version: SELECT version ();

Note: If the downloaded Jar package version does not support the MySQL database, you may get an error when running Jmter: no suitable driver found for jdbc:mysql//...

to be Jmeter Add Jar file

Unzip the. zip file after download and put Mysql-connector-java-x.x.x-bin.jar (example: Mysql-connector-java-commercial-5.1.25-bin.jar) in the Lib directory under the JMeter installation directory (Example: D:\Program files\apache-jmeter-2.13\lib)

Second, configure the JDBC Connection configuration:

Important Parameter Description:

    • Variable Name: Database connection pool names, we can have more than one JDBC connection configuration, each can be a different name, in the JDBC request can be selected through the name of the appropriate connection pool for use.
    • Database URL: Url,jdbc:oracle:thin: @host_ip or machine_name:oracle listener listening port:The name of the Oracle instance ( This information can be found in the Tnsnames.ora file in the Oracel installation directory)
    • JDBC Driver class:JDBC driver
    • Username: User Name of database login
    • Passwrod: Password for database login

Third, configure the JDBC Request:

1. Important Parameter Description:

Variable Name: The name of the database connection pool needs to be consistent with the Variable name Bound pool name of the JDBC Connection configuration

Query: Fill in the SQL statement do not add ";"

Parameter valus: Parameter values

Parameter types: Parameter type, refer to: Javadoc for Java.sql.Types

Variable names: variable name to save SQL statement return result

Result variable Name: Creates an object variable that holds all returned results

Query timeout: Queries Time out

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

2. Execution Result:

Four: JDBC request parameterization:

Method (i): Define variables and use variables in SQL Quety:

1. Define three variables in test plan (you can also use parameterization: JMeter parameterization):

2. Reference in SQL query using the ${variable name}:

Method (b): Use in SQL Quety "? "As a placeholder and pass parameter values and parameter types, such as:

1, the passed parameter value is a constant, such as passing 3 constants: 10,accountingnew YORK:

2. The parameter value passed is a variable, as in ${dname}:

Five: Variables names parameter use method:

JMeter's official website explains that if you set a value for this parameter, it will save the data returned by the SQL statement and the total number of rows that return the data. If the SQL statement returns 2 rows, 3 columns, and variables names is set to A,,c, the following variables are set to:

a_#=2 (total number of rows)
a_1= 1th column, line 1th
a_2= 1th column, line 2nd
c_#=2 (total number of rows)
c_1= 3rd column, line 1th
c_2= 3rd column, line 2nd

    • If the return result is 0, then a_# and c_# will be set to 0, and the other variables will not set the value.
    • If you return 6 rows of data for the first time and return only 3 rows for the second time, then the first number of 3 rows of data variables will be cleared.
    • You can use ${a_#}, ${a_1} ... To get the corresponding value

Example:

We still use the above database, to find out all the data, Dept table has 3 fields, 4 records (forgotten can go back to the first step to see)

1. Add a JDBC request named Select4, add a debug sampler to view the results of the output, set variables name to A,b,c:

2. Execution Result:

VI: Result variable Name parameter use method:

If you set a value for this parameter, it creates an object variable, saves all returned results, and gets the exact value of the method: Columnvalue = Vars.getobject ("Resultobject"). Get (0). Get ("Column Name")

Execution Result:

Seven: Database-driven classes and URL formats:

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:@//host:port/service OR

jdbc:oracle:thin:@ (description= (address= (Host={mc-name})

(PROTOCOL=TCP) (Port={port-no})) (Connect_data= (Sid={sid})))

Ingres (2006)

Ingres.jdbc.IngresDriver

Jdbc:ingres://host:port/db[;attr=value]

MSSQL

Com.microsoft.sqlserver.jdbc.SQLServerDriver

Or

Net.sourceforge.jtds.jdbc.Driver

Jdbc:sqlserver://ip:port;databasename=dbname

Or

jdbc:jtds:sqlserver://localhost:1433/"+" library "

Official website Example (MySQL): http://jmeter.apache.org/usermanual/build-db-test-plan.html

About the application of JDBC-related parameters in JMeter: http://f.dataguru.cn/thread-554702-1-1.html

Go: How to use JDBC request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.