9.5 Using DataSet
In Section 9.3, Database Select, we saw how to process the results set obtained from executing a
SELECT query. If we want to receive only a filtered set of rows, such as only cities with temperature values below 32, we can set up the query accordingly. Alternatively, we can receive the
result as a groovy.sql.DataSet to filter data. Let’s examine this further.
The
dataSet
method of the Sql class takes a table’s name
and returns a virtual proxy—it does not fetch the actual rows until we iterate. We can then iterate over the
rows using the
each
method of the DataSet (like the
eachRow
method of Sql). In the following code, however, we’ll use the
findAll method to filter the results to obtain only cities with ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access