Processing XML from the DB in JMeter

Now this one is a bit out there but maybe you’ll need this someday.

Sometimes clever developers put XML into table fields as BLOB or CLOB (well actually it’s a special BLOB just for XML so standard SQL won’t quite work as expected). Not sure why one would do that but not my place to comment. Anyway it’s a real pain if your holy grail is burried somewhere in that XML.So after some serious googling and trial and error I finally managed to do this in Groovy.

Note that this is for DB2 but should be the same or similar for other DB’s.

import groovy.sql.Sql

String someVariable= vars.get('someVariable')
sql = Sql.newInstance("jdbc:db2://", "username", "password",

sqlQuery = """
AS OutXML FROM testdb
where ID = """ + someVariable

sql.eachRow(sqlQuery) { row ->


As you can see above, should your XML file be bigger than 32k you will run into some issues. There are ways around this. One way is to dig in to the XML code in the SQL statement and only extract elements you want. See XMLQUERY and similar for that.

You can also just do this in a JDBC Request Sampler too. Then you’ll need to trawl through the XML wih the JMeter functions which is a bit limiting. Groovy lets you slurp in the XML or you can just use Regex matching to get what you want.

by Oliver Erlewein





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s