jmeter capture jdbc value in global variable

jmeter capture jdbc value in global variable  using -'jdbc,properties,global-variables,jmeter'

I'm very new to Jmeter and I'd like to know if there is some way to store the result of a query in a global variable to use in a different thread.

In other words, I need a set-up thread that sets a start-date and end-date (2 values) from the DB.
Then, in a second thread (the main thread), I have to use the start-date and end-date as parameters for the tests.

Is this possible?

Thanks in advance!,

asked Oct 19, 2015 by sandeep bhadauria
0 votes

2 Answers

0 votes

Use the following elements:

Organize them as following: enter image description here

It will work as following:

  1. JDBC Connection Configuration will setup the connection to DB, name Variable name so that it matches Variable name of JDBC Request, in my case I name it conn

  2. Setup Thread Group will run query through JDBC Request and store result in variables

  3. Beanshell sampler with use the value and store it as a property so it can be shared by all threads.

Note the following:

  • The variable names of JDBC Request must match the number of columns returned by your SQL Query, note in example I have 3 columns, I put 3 variables, and will use clt_nom_1 name as I ensure there is only row returned by query

    • In Bean Shell sampler I put the following code:

    • clt_nom_1 is named like this because it's the first row value

    • Finally in Thread Group I can use property toto through:


JDBC Request Example

You could also replace BeanShell sampler by a debug sampler named:


which would store variable in property

answered Oct 19, 2015 by manju bhargava
0 votes

I have done it differently: I created a BSF PostProcesser use 'Javascript' as the language:

var strData = prev.getResponseDataAsString(); //This is a string delimited with character return
var listData = strData.split('\n');

Then you can do all sort of things like from your list data, such as vars.putObject.

NOTE:It works with SELECT query on JDBC request.

answered Oct 19, 2015 by bhavin