I also add debug sampler into the test plan, variable "id" has the value shown in the result tree. Observe the issue from the log file "jmeter.threads.JMeterThread: Error while processing sampler 'try integer' : java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String". Do you have any idea how to get the integer variable used in the other sampler? –
mingJan 2 '14 at 5:23
When you use putObject method just cast your integer into String using toString() method.vars.putObject("id", id.toString()); –
olyvJan 2 '14 at 6:58
If i use string it works fine for my select statement where i can change the type to varchar. I have one insert statement for one jdbc request required number parameter. When i pass "${id}" not working if cast it to String.–
mingJan 2 '14 at 7:51
I'm not sure I've got your option. If you have select query you write it as select * from table where condition = ${id}. Supposing your variable has value 5 (it is string, because user defined variable stores only string) next query will be executed select * from table where condition = 5. If you need varchar in the SQL query you write select * from table where condition = '${id}' and next will be executed select * from table where condition = '5'. JMeter HTTP or JDBC sampler treat ${variable} the next way: just get the text from variable and put it into sampler body. Is it the answer? –
olyvJan 2 '14 at 8:34
Thanks for the details. Method vars.putObject can store any type of object for user defined variable, for example integer. I wonder if there is some way to get the variable whose type is not string. I have one insert query [insert into table (id number) values (${id})] required integer in one jdbc request using the variable storing integer defined in JSR223 sampler. As you have mentioned, ${id} type is string, any way to convert to integer? –
mingJan 2 '14 at 10:30
putObject
method just cast your integer into String usingtoString()
method.vars.putObject("id", id.toString());
– olyv Jan 2 '14 at 6:58select * from table where condition = ${id}
. Supposing your variable has value 5 (it is string, because user defined variable stores only string) next query will be executedselect * from table where condition = 5
. If you need varchar in the SQL query you writeselect * from table where condition = '${id}'
and next will be executedselect * from table where condition = '5'
. JMeter HTTP or JDBC sampler treat ${variable} the next way: just get the text from variable and put it into sampler body. Is it the answer? – olyv Jan 2 '14 at 8:34