Skip to content

Instantly share code, notes, and snippets.

@kousen
Created November 20, 2019 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kousen/5cbc63501174e77f912eeba7dedc9b20 to your computer and use it in GitHub Desktop.
Save kousen/5cbc63501174e77f912eeba7dedc9b20 to your computer and use it in GitHub Desktop.
@GrabConfig(systemClassLoader=true)
@Grab('com.h2database:h2:1.4.200')
Sql sql = Sql.newInstance(url: 'jdbc:h2:~/astro', driver: 'org.h2.Driver')
sql.execute '''
create table if not exists ASTRONAUTS(
id int auto_increment primary key,
  name varchar(50),
  craft varchar(50)
  )
'''
response.people.each {
sql.execute "insert into ASTRONAUTS(name, craft) values ($it.name, $it.craft)"
}
sql.close()
@kousen
Copy link
Author

kousen commented Nov 20, 2019

Saving the astronauts in a database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment