How Can I Extract The Column Names From An SQL Query Result?


I’ve managed to successfully connect to a database and have the following bit of code which returns the result of an sql query:

def result_set = sql.rows(sql_query)

Now, when I print result_set, I also get the column name included into the data like so: [column1:103988], [column1:103835], [column1:103700], [column1:103052], [column1:103421]. Is there a simple way that I can extract the “column1” value from this so I could later remove it and instead get the following result? [103988], [103835], [103700], [103052], [103421]

You have a variable named sql in the following statement.

def result_set = sql.rows(sql_query)

Please tell us which type of class the variable sql is of.

Is it an instance of groovy.sql.SQL ?

Please show us how you do it.
Does it look like this?

println result_set