In JMeter, JDBC PreProcessor is used to fetch the data from the database which can be used in the sampler’s request. Let’s try to understand with an example. Consider you have a performance testing scenario where a customer needs to cancel the existing order. The order number is available in the database against customerID. So, your approach would be to get the orderID using customerID from the database and send the order cancel request.
Once you add JDBC PreProcessor under cancel request, it executes the select query to fetch orderID and then pass this value to cancel request sampler.
To use JDBC PreProcessor in the script, firstly you need to set-up the JDBC connection with the database. For this purpose, you need to add JDBC Connection Configuration element under Test Plan (if you have more than 1 thread and use the same database configuration).
Add JDBC PreProcessor under the sampler for which you need data from the database.
Write down the SQL statement inside SQL Query section
Run the test and see the result
How to add ‘JDBC PreProcessor’?
You can follow the below steps:
- Select the appropriate element where you want to fetch the data
- Thread Group
- Right-click on the node
- Hover the mouse over ‘Add’
- Hover the mouse over ‘PreProcessor’
- Click ‘JDBC PreProcessor’
What are the input fields of the ‘JDBC PreProcesso’ element?
‘JDBC PreProcessor’ has the following input fields:
- Name: To provide the name of the preprocessor
- Comments: To provide arbitrary comments (if any)
- Variable Name of Pool declared in JDBC Connection Configuration: The name of the connection pool given in the JDBC Connection Configuration.
- Query Type: Choose the type of SQL query statement like Select, Update, Callable, Commit, Rollback etc.
- Query: In this section, you can write down the SQL statement which is used to perform the operation before the sampler executes.
- Parameter Values: If parameters are used in the SQL query then parameter values can be provided here. Parameter values must be comma-separated and in the order as same as they are used in the SQL statement.
- Parameter Types: The parameter type of the values defined in the ‘Parameter Values’ field like VARCHAR, INTEGER etc. They are also comma-separated and in the same order as parameter values are written.
- Variable Names: The list of the variables in which fetched data from the database will be stored. Variable names are also in comma-separated format.
- Result Variable Name: The key-values variable in which data-set value is stored. This is an optional attribute.
- Query Timeout (s): JMeter waits for query response until given timeout (in seconds) reaches.
- Handle ResultSet: The process, how the fetched result will be handled like Stored as String, Stored as Object etc.