I want to generate dynamic HTTP Requests for different URL paths with credentials. For that I need to fetch the URLs from a database, so I have created one JDBC Connection Configuration and set JDBC Request(Pre-Processors) with my Select statement.

Now I need to write the output of my select statement to a CSV data file. Can I do that or do I have to loop through this controller?

1 Answer 1


You can do it using JSR223 PreProcessor as follows

  1. Define "Result Variable Name" like resultSet (you can use anything meaningful here)

    JDBC Result Variable Name

  2. Add JSR223 PreProcessor to your test plan (just make sure it is located below the JDBC PreProcessor)
  3. Put the following code into "Script" area:

    resultSet = vars.getObject("resultSet")
    result = new StringBuilder()
    for (Object row : resultSet ) {
        iter = row.entrySet().iterator()
        while (iter.hasNext()) {
            pair = iter.next()
    org.apache.commons.io.FileUtils.writeStringToFile(new File("foo.csv"), result.toString(), "UTF-8")

If everything goes well you should see foo.txt in JMeter's "bin" folder, the file will contain your SQL query output data in CSV format.

See Debugging JDBC Sampler Results in JMeter article for more information on how to work with JDBC test elements results in JMeter tests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.