July 2013
Intermediate to advanced
370 pages
8h 27m
English
We can get the data from the database and create different representations using Groovy builders.
Here is an example that creates an XML representation (see Section 17.1, Building XML) of the data in the
weather table:
| WorkingWithDatabases/Weather.groovy | |
| | bldr = new groovy.xml.MarkupBuilder() |
| | |
| | bldr.weather { |
| | sql.eachRow('SELECT * from weather') { |
| | city(name: it.city, temperature: it.temperature) |
| | } |
| | } |
The code produces this XML output:
| WorkingWithDatabases/Weather.output | |
| | <weather> |
| | <city name='Austin' temperature='48' /> |
| | <city name='Baton Rouge' temperature='57' /> |
| | <city name='Jackson' temperature='50' /> |
| | <city name='Montgomery' temperature='53' /> |
| | <city name='Phoenix' temperature='67' /> |
Read now
Unlock full access