Setting Up the Database

We’ll use MySQL in the examples in this chapter; however, we can use any database that we can access using JDBC. First let’s set up the database we’ll use in the examples, with a table named weather. The table contains names of and temperature values for some cities.

It’s easier to set up the database using an automated script than to do it manually. So, let’s create a SQL script to build the database:

 
create​ ​database​ ​if​ ​not​ ​exists​ weatherinfo;
 
use weatherinfo;
 
 
drop​ ​table​ ​if​ ​exists​ weather;
 
create​ ​table​ weather (
 
city ​varchar​(100) ​not​ null,
 
temperature ​integer​ ​not​ null
 
);
 
 
insert​ ​into​ weather (city, temperature) ​values​ (​'Austin'​, 48);
 
insert​ ​into​ weather (city, ...

Get Programming Groovy 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.