0
votes

enter image description hereI am running a query via JDBC request and I am able to get the data and place it in a variable array. The problem is I want the values of the variables to be saved to a text file. However, each variable is being given a unique number appended to it i.e. SCORED_1, SCORED_2,SCORED_3 etc. I am using a beanshell post processor to write to the text file. The problem is I unless I define A LINE Number. How can I get all results from a SQL query and dump them into a single variable without the variables separated by brackets and line separated on their own row.

 import org.apache.jmeter.services.FileServer;

 // get variables from regular expression extractor 
 ClaimId = vars.get("SCORED _9"); // I want to just use the 
 SCORED variable to contain all values from the array 
 without "{[" characters.


  // pass true if want to append to existing file  
 // if want to overwrite, then don't pass the second 
 argument
 FileWriter fstream = new FileWriter("C:/JMeter/apache- 
 jmeter-4.0/bin/FBCS_Verify_Final/Comp.txt", true);
 BufferedWriter out = new BufferedWriter(fstream);
 out.write(ClaimId);
 out.write(System.getProperty("line.separator"));
 out.close();
 fstream.close();
2

2 Answers

0
votes

We are not telepathic enough to come up with the solution without seeing your query output and the result file format.

However I'm under impression that you're going into wrong direction. Given you're talking about {[ characters it appears that you're using Result Variable Name field

enter image description here

which returns an ArrayList which should be treated differently

enter image description here


However if you switch to Variable Names field

enter image description here

JMeter will generate a separate variable per each result set row and it should be much easier to work with and eventually concatenate

enter image description here

More information:

0
votes

JDBC request>Enter a Variable Name> Store as string>Add a Beanshell PostProcessor and add the following script.

    import org.apache.jmeter.services.FileServer;
{
FileWriter fstream = new FileWriter("C:/JMeter/apache-jmeter-4.0/bin/FBCS_Verify_Final/Comp.txt", false);
BufferedWriter out = new BufferedWriter(fstream);



 Count = vars.get("SCORED_#");
 Counter=Integer.parseInt(vars.get("SCORED_#"));
 for (int i=1;i<=Counter;i++)

 {

 ClaimId = vars.get("SCORED_"+i);
 out.write(ClaimId);
 out.write(System.getProperty("line.separator"));

 }

 out.flush();
 out.close();
 fstream.close();

}