JMeter – JDBC PreProcessor

JMeter - JDBC PreProcessor

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).

JMeter - JDBC PreProcessor
Figure 01

Add JDBC PreProcessor under the sampler for which you need data from the database.    

JMeter - JDBC PreProcessor - Example
Figure 02

Write down the SQL statement inside SQL Query section

JMeter - JDBC PreProcessor - SQL Query
Figure 03

Run the test and see the result

JMeter - JDBC PreProcessor - Test Execution
Figure 04

How to add ‘JDBC PreProcessor’?

You can follow the below steps:

  1. Select the appropriate element where you want to fetch the data
    1. Thread Group
    2. Controller
    3. Sampler
  2. Right-click on the node
  3. Hover the mouse over ‘Add’
  4. Hover the mouse over ‘PreProcessor’
  5. Click ‘JDBC PreProcessor’

What are the input fields of the ‘JDBC PreProcesso’ element?

‘JDBC PreProcessor’ has the following input fields:

  1. Name: To provide the name of the preprocessor
  2. Comments: To provide arbitrary comments (if any)
  3. Variable Name of Pool declared in JDBC Connection Configuration: The name of the connection pool given in the JDBC Connection Configuration.
  4. Query Type: Choose the type of SQL query statement like Select, Update, Callable, Commit, Rollback etc.
  5. Query: In this section, you can write down the SQL statement which is used to perform the operation before the sampler executes.
  6. 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.
  7. 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.
  8. 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.
  9. Result Variable Name: The key-values variable in which data-set value is stored. This is an optional attribute.
  10. Query Timeout (s): JMeter waits for query response until given timeout (in seconds) reaches.
  11. Handle ResultSet: The process, how the fetched result will be handled like Stored as String, Stored as Object etc.

Leave a Reply

Your email address will not be published. Required fields are marked *