Andrii Muzychka
Andrii Muzychka

Reputation: 59

Jmeter use data from JDBC Request in HTTP Request

I need to use data from RDBC request in HTTP request. Before ask this question I read these topics:

but I still don't know how to do this.

Test Structure:

JDBC Connection Configuration
JDBC Request
ForEach Controller
    BeanShell Sampler
    HTTP Request

My steps:

  1. Created JDBC Request that return data in 2 columns and added variable names (years, elements).
  2. Next I use ForEach Controller to read data from rows. Input variable prefix: years, elements and Output variable name: years1, elements1;
  3. parse data from variables with BeanShell Sampler:

    String yearsRange = vars.get("years1"); String year =
    yearsRange.split("-")[1];
    
    String ElementsStr = vars.get("elements1"); String element =
    ElementsStr.split(" ")[1];
    
    vars.put("year", year);
    vars.put("element", element);
    
  4. And now I create HTTP Request with parameters:

    year ${year};
    element ${element};
    

    I know that problem is with ForEach Controller (if I set one variable, all works fine) but I don't have any idea how to make it work with 2 or more variables.

Please give me advice what i'm doing wrong?

Upvotes: 2

Views: 4888

Answers (1)

Dmitri T
Dmitri T

Reputation: 168197

Use Counter config element or __counter() function to iterate 2nd variable like:

Foreach Controller

View Results Tree

And I don't think you need Beanshell Sampler as JDBC Request returns resulting variables in the form which ForEach Controller can consume, like:

var_1=foo
var_2=bar
anothervar_1=baz
anothervar_2=somethingelse

See Debugging JDBC Sampler Results in JMeter guide for more detailed explanation.

Upvotes: 1

Related Questions