How to use JMeter (DB testing) |
Subscribe me on new discussions

How to use JMeter (DB testing)

Views: 1510

Apache JMeter™

The Apache JMeter™ application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.

How to create JMeter Test for DataBase

Database Testing is required to test DB for errors.To test DB using Jmeter, first we need to download and attach Database connector with Jmeter.

Step 1 - Download MySQL connector for JMeter

  • Download mysql-connector-java-8.0.16 from here.
  • Choose Platform Independent from the list and download Platform Independent (Architecture Independent), ZIP Archive

Step 2 - Place the MySQL connector

  • Extract the downloaded file in \apache-jmeter-5.1.1\lib\
  • Make sure that a file named mysql-connector-java-8.0.16.jar is there inside the lib folder

Step 3 - Start Jmeter

  • Download JMeter from here.
  • Extract the zip file in your preferred location
  • In the bin folder there will be a jmeter.bat file, run it.
  • The JMeter window will show up

Step 4 - Create a TestPlan

TestPlan is created to check different tests(Database in this case) of different pages under a single project

  • Name the test plan. I have given DataBase Test

Step 5 - Create a Thread Group (Users) 

Thread group is a way to introduce virtual users for our test.

  • Follow this to create a thread group DataBase Test(right click) >Add>Threads(Users)>Thread Group
  • I have given a name to the thread group Thread for DB
  • In thread properties there will some parameters
  • Number of thread is the number of users
  • Ramp-up time is time in milliseconds to introduce a new user for the test.
  • Loop count is the period for the test execution. If loop count is set forever then the test will execute until the user forcefully stop the execution

Step 6 - Create DataBase if you don't have(Optional)

  • provides free database for testing purpose
  • Here is the details of my database. There are 2 rows and 4 columns in the Test table of databasetest024 DB.
  • Login to your database using the username & password you provided at the time of sign-up


Step 7 - Add Config Element to the Thread Group

Config Element is needed to configure elements of various external sources.In this case we have to configure the database we want to test

  • We will use JDBC element to configure our database
  • Add a config element Thread for DB(right click) >Add>Config Element>JDBC Connection Configuration
  • Here some parameters need to be set correctly. Follow this steps carefully.Scroll down to Database connection configuration
  • The general format for a JDBC URL for connecting to a MySQL server is as follows, with items in square brackets ([ ]) being optional: jdbc:mysql://[host1][:port1][,[host2][:port2]]...[/[database]]
  • Example: jdbc:mysql:// for my test. Once you signup in ,they will send you a email that contains hostname & port
  • JDBC driver class for MySQL is com.mysql.jdbc.Driver . You can choose if you have other database
  • Username and Password is same that you provided to login to the database
  • Give a name(any) to the Variable Name for created pool
  • Keep the rest of the parameters as it is

Step 8 - Add sampler(JDBC request)

We have successfully configured our database, now we are ready to request data from the database using sampler. in this case we will use JDBC sampler to test database.

  • Add sampler Thread for DB(right click) >Add>Sampler>JDBC Request
  • Use the same name as given in Variable Name for created pool
  • Inside the query box type the table name whose data we want to fetch using this command select * from TABLENAME . In my case I want to fetch data from Test table so I have written select * from Test
  • Keep rest of the parameters as it is

Step 9 - Add Listener

To check results of DB testing we will use Results Tree as a listener

  • Add listener Thread for DB(right click) >Add>Listener>View Results Tree

Step 10 - Run & Validate the Test

  • Run the test using start button in the toolbar
  • In results tree we can see three things i.e. sampler result,requested data,response data
  • If all the steps are followed correctly then we can results as follows

Sampler result(Response message will be ok if connection is successful)

Requested data(same as what I have written inside query box)

Response data(will show the same data saved in MySQL database)

If everything is done correctly then there will be no error in the test result as compared to the data we have in the MySQL database. In this way we can test database using JMeter automation tool. In case of any doubt leave a comment below.

Thanks for your patience. That's the end of the article.

Karma: {{ total }}
Published: 11 months ago by Raja
QAProvider Team at 2019-06-25 07:05:05
Karma: {{ total }}

We have tried to do a little bit complex test mixing DB checks and HTTP requests.


  1. Get views count of discussion, store data
  2. Send GET request on discussion
  3. Check views increased on 1

Configuring with JMeter:

  1. Add JDBC request to get views count for exact discussion. Add variable name to store the value, we gave a name views_cnt

2. Add HTTP request

3. Add next JDBC request

4. Add assert. Assert function to get incremented value will be ${__intSum(1, ${views_cnt_1})}. Very strange language :)

5. Have a look on results.

Configuration of JMeter looks too complex for tasks like that :) But it is still possible.

We think that here JMeter would be nice for another type of test:

  1. Send 1000 get requests on discussion view in 1 second.
  2. Check that discussion views incremented exactly on 1000.
Raja replied to QAProvider Team comment at 2019-06-25 08:20:31
Karma: {{ total }}

For that Assert portion,to increment a value with the requested value JMeter uses a special function intsum . You can check details of this in Tools>Function Helper , Select intsum from the dropdown menu, set 1/2 integer values to increment and set the variable name as you like. You can see result like this and the  function syntax will be autogenerated(Happened in your case too). In your case you have requested the views of that particular discussion whose result is stored in the variable views_cnt and when you increment views_cnt  by 1 , JMeter will store the new result in views_cnt_1(auto-generated by JMeter). that's why the function syntax is ${__intSum(1, ${views_cnt_1})}

ARJUN KUMAR at 2019-06-25 07:35:23
Karma: {{ total }}

Sir !!! This article is indeed very worthy , skillful & henceforth explained in a very appropriate manner....Well done !!!👍👍👍