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!, Nahuel
Use the following elements:
JDBC_Connection_Configuration
JDBC Request
BeanShell Sampler
setUp Thread Group
Organize them as following:
It will work as following:
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
Setup Thread Group will run query through JDBC Request and store result in variables
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:
props.put("toto",vars.get("clt_nom_1"));
clt_nom_1 is named like this because it's the first row value
Finally in Thread Group I can use property toto through:
${__P(toto)}
You could also replace BeanShell sampler by a debug sampler named:
${__setProperty(toto,${clt_nom_1})};
which would store variable in property
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With