Question

I used jmeter recently and I try to get some data from a jdbc request and send them in a spring service with http request.

Let me explain more specifically.

I use this query:

SELECT MEMBER_ID, 
       PERSON_NAME, 
       PERSON_SURNAME 
FROM MEMBER, 
     PERSON 
WHERE CDT_MEMBER_ID = CDT_PERSON_ID

From the above request the values inserted in these variables: id, name, surname, where i have define in "Variables names" field of JDBC request control panel. (in each variable returned 10 values, so i treat them as arrays)

Then I use a "For each" controller tried to loop into the values but I can't. Into the "For each" controller panel, if I set as "Input variable prefix" (e.g.) the id and as "Output variable name" variable, loop works correctly and then with an inner http request I send the ${variable} at the spring service.

But I want to sent a row each time as a String (id[i] + name[i] + surname[i]). How can do this?

I also try to write some scripts to define this string with beanshell pre-processor without any effectiveness.

Was it helpful?

Solution

Ok, as far as I have realised, I have to use a "BeanShell Sampler" between "JDBC Request" and "ForEach Controller". Then using beanShell script I take the length of the arrays, scripting:

Integer x = Integer.parseInt(vars.get(dataId_#)); 

and in a for loop i insert the data in a String array like these:

String[] dataArray = new String[x];
for (i = 0; i < x; i++) {
vars.put("dataArray_" + i, vars.get("dataId_" + i) + " " + vars.get("name_" + i) + " " + vars.get("surname_" + i));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top