Leeladharan Achar - alias - leelu ~ blogging...hola mi amigos..'s Blog

Posted July 19, 2018   196 views

running multiple sql queries in jmeter

Below are the steps to be followed to run multiple queries in jmeter

I did some google search and here were the pages where i landed to see how it's done

https://stackoverflow.com/questions/25443582/jmeter-launch-several-sql-requests

But, actual steps on how to do it was not mentioned. So below are the steps to do the same.

First have all sql queries to be executed in a sql file in below format
select * from table1;
select * from table2;
select * from table3;
....
select nth data from nth table;

now save this in a required_file_name.sql

Then open jmeter.

In that, Right click on Test Plan => Add Thread Group =>

Name of Thread group => sample_sql_test
Number of Threads => 1 (only will run as single user)
RampUp period => 1 (only for testing purpose)
Loop Count => 1 (number of times the sql file should be run by each thread)

Save it

Now right click on created thread group and Add Config Element=> CSV Data Set Config

Name => keep default or use any name
FileName => select the sql file saved
VariableName => sqlQuery
Ignore First Line => False
Delimiter => ;
Allow quoted data => True
Recycle On EOF => False
Stop Thread On EOF => False
Sharing Mode => All Threads

Save it

Now right click on created thread group and Add Config Element => JDBC Connection Configuration

Name  => sql_test_db
Variable Name => sql_test_db

Jump to Database Connection Configuration (I am using postgresql)

DatabaseURL => jdbc:postgresql://ip_address:port/database_name
JDBC Driver Class => org.postgresql.Driver
UserName => db connection role username
Password => connection role password

Save it Now right click on created thread group and Add Sampler => JDBC Request

Name => keep default or name it as required
variable name bound to pool => sql_test_db (specify the variable name given  in JDBC Connection configuration)
Query Type => SELECT Statment
Query Text Box => ${sqlQuery}

Save it

Now right click on created thread group and Add Listener => View Results Tree

Save it

That's all save the template and run the test.

Problems faced during this process

Postgresql driver not found.

Download the postgresql driver jar file from https://jdbc.postgresql.org/download.html

We need to place this Jar file in the the bin folder of jmeter then restart jmeter.