Another way to parametrize your performance scripts is to use database data through JDBC. JDBC is an application programming interface that defines how a client can access a database.
First of all, download the JDBC driver to your database (refer to the database vendor). For example, mysql driver can be found here. Then, you can add it by adding the .jar file to the test-plan by using the form below:
But it is better to add the Jar file in lib folder and restart JMeter.
After that, configure the database connection by using the ‘JDBC Connection Configuration’ element. Like this: Right click on Thread Group -> Add -> Config Element -> JDBC Connection Configuration
‘JDBC Connection Configuration’ parameters:
In our case we need to setup the mandatory fields only:
The rest of the fields in the screen can be left as defaults:
Let’s assume that we store test user credentials in the database:
Now when the database connection is configured, we can add the JDBC request itself and use its query to get all the credentials from database: Right click on Thread Group -> Add -> Sample -> JDBC Request
By using the ‘Select Statement’ query and ‘Variable Names’ we can parse the response to custom variables.
We will now have JMeter variables that can be used further in subsequent requests. Specified variables will be created with incremental suffix (email_1, email_2, email_3…..).
To use these variables in the ‘Login request’, we need to add a counter that will be used to access the right values from the JDBC query response. To add the ‘Counter’ element in JMeter: Right click on Thread Group -> Add -> Config Element -> Counter
After that, we can update the ‘Login request’ using the __V function. This returns the result of evaluating a variable name expression and can be used to evaluate nested variable references:
The specified configuration is enough to use database values to run the script across different users: