0

I know they advice to get a cell value this way:

columnValue = vars.getObject("resultObject").get(0).get("Column Name");

as stated on jMeter doc : component reference : JDBC_Request.

But: How to access the same RS cell value by just a number of the column?

RS.get(0).get(4);

...instead of giving it a String of column Name/Label.

edit 1: Lets use Groovy/Java, instead of BeanShell. Thanks.

edit 2: The original motivation was the difference between column Name / Label, as these seem to be not fully guaranteed (? seems to be not clear here, not to me), especially due case-sensitivity ("id"/"ID", "name"/"Name"/"NAME" ..)

Franta
  • 986
  • 10
  • 17
  • 1
    answering your edit 2: definitely use `row.entrySet()` or similar way, as it's the best way to iterate through all entries in map. – timbre timbre Nov 06 '17 at 19:01

2 Answers2

2

It should be something like:

String value = (new ArrayList<String>(vars.getObject("resultObject").get(0).values())).get(4)

More information: Debugging JDBC Sampler Results in JMeter


Be aware that according to HashMap documentation:

This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

So the order of columns might be a big question mark.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
1

The row itself is a HashMap, defined in source code as:

HashMap<String, Object> row

So using BeanShell syntax, you could get it as

row = vars.getObject("resultObject").get(0); // returns HashMap

In HashMap, you cannot access item (column) by ID. You could, however, apply one of the methods described here, but HashMap doesn't guarantee order, so you cannot be sure what "column 4" will contain.

If you want to be able to loop through all columns, it's better to do it in a Map style, not by index. For example using entrySet() with BeanShell:

for(Map.Entry entry : row.entrySet())
{
    log.info(entry.getKey() + "=" + entry.getValue());
}

See various ways to iterate through Map here.

timbre timbre
  • 12,648
  • 10
  • 46
  • 77