Database test plan tutorial in jmeter

Now we are going to see how to configure, run and analyze the results of a test against a MySQL Database. This example is about MySQL but it can be done using any other kind of DB like Oracle, MongoDB or others.
  • Install MySQL
If you do not have MySQL installed in your computer, you can download it from http://dev.mysql.com/downloads/ and install the MySQL server, it is very easy.
  • Download the MySQL driver
Download mysql connector (mysql-connector-java-5.1.6) and copy it in the lib directory of jmeter C:\jmeter\apache-jmeter-2.11\lib.
  • Start MySQL
Start the DB server so that you can make queries against it.
  • Create database
You can create a database as you want, here is just an example of a very simple one:
01create database jmeter;
02 
03use jmeter;
04 
05create table jmeter_stuff(id int, name varchar(50), description varchar(50));
06 
07insert into jmeter_stuff(id, name, description)VALUES(1, "dani""the boss");
08 
09insert into jmeter_stuff(id, name, description)VALUES(2, "topo""the worker");
10 
11insert into jmeter_stuff(id, name, description)VALUES(3, "tupac""the other");
  • Create a test plan
Do the same actions as in the chapter before to create a test Plan using a new Thread Group, a new configuration element of the type JDBC configuration and a new request (sampler) of the type JDBC, add also a listener to parse and view the results in the same way as we did in the example before.
The only difference is the type of the sampler, in this case JDBC Sampler.
  • JDBC Sampler
Give a meaningful name to the Variable Bound to Pool and write some SQL statement:
1select * from jmeter_stuff;
db request configuration
  • JDBC Connection configuration
Add a new JDBC Connection Configuration to the sampler.
right click on the JDBC sampler -> add connection configuration
Change the parameters as follows:
1Variable Bound to Pool= same name as in the sampler
2Database URl=jdbc:mysql://localhost:3306/jmeter
3JDBC Driver class=com.mysql.jdbc.Driver
4username=
5password=
6 
7set username and password to your MySql credentials.
db connection configuration
  • Save the plan and execute it.
  • View the results using the listener configured before.
You can verify and check the output in the same way as in the HTTP request test plan, you can also add preprocessors, post processors, assertions or any other kind of element that you may need.

db results response data
In this case the output is the results of the select statement.
You can use this kind of samplers for updating data as well by changing the SQL statement in the sampler configuration.
In the following screen capture is the basic information about the request response results:
db results response