July 2013
Intermediate to advanced
370 pages
8h 27m
English
We can use the DataSet object to add data, not just filter data.
The
add
method accepts a map of data to create a row, as shown in the following code:
| WorkingWithDatabases/Weather.groovy | |
| | println "Number of cities : " + sql.rows('SELECT * from weather').size() |
| | dataSet.add(city: 'Denver', temperature: 19) |
| | println "Number of cities : " + sql.rows('SELECT * from weather').size() |
The following output shows the effect of executing that code:
| | Number of cities : 8 |
| | Number of cities : 9 |
More traditionally, however, we can insert data using the Sql class’s
execute
or
executeInsert
method, as shown here:
| WorkingWithDatabases/Weather.groovy | |
| | temperature = 50 |
| | sql.executeInsert("""INSERT INTO weather (city, ... |
Read now
Unlock full access