JMeter get jdbc request data and send each with http post request in a spring service how-to

馋奶兔 提交于 2019-12-11 13:55:49

问题


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.


回答1:


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));
}


来源:https://stackoverflow.com/questions/21741264/jmeter-get-jdbc-request-data-and-send-each-with-http-post-request-in-a-spring-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!