1

Looking to utilize jmeter for some automated testing but facing a problem. preliminary to my tests I want to run a query on my DB and then store the result in a text file.

I thought I'd do it via a JDBC request as such:

(blurred out some stuff, but you get the idea)

Then immediately after I want to do some post-processing that writes the result to our file:

enter image description here

I've tried, too, putting the paramater passed to vars.get in quotation marks, but I get no such luck. Jmeter does write a file, but that file is empty, and if I run the query independently, it does return results.

Does anybody know how to get this desired behavior?

f_puras
  • 2,521
  • 4
  • 33
  • 38
PinkElephantsOnParade
  • 6,452
  • 12
  • 53
  • 91

1 Answers1

2

If you look into jmeter.log file you should see a Beanshell Related error.

This is due to "Result Variable Name" being an ArrayList, not String, hence

  1. You need to use vars.getObject() method instead of vars.get();

  2. Ensure you quote the variable name

  3. Remove the ";" at end of SQL Query

  4. You need to iterate the ArrayList somehow or serialize it to file.

  5. If result set is large it's better to consider doing it via JSR223 Sampler using "groovy" as a language as Beanshell has some performance limitations. See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! guide for benchmarking results and instructions on how to setup groovy scripting engine support.

  6. To write the output to a file , see :

    Append data into a file using Apache Commons I/O

If you decide to use Groovy it will be even easier :

Community
  • 1
  • 1
Dmitri T
  • 159,985
  • 5
  • 83
  • 133