Skip to content

Instantly share code, notes, and snippets.

@nkonev
Created October 9, 2015 23:24
Show Gist options
  • Select an option

  • Save nkonev/6123537447722f3e81f7 to your computer and use it in GitHub Desktop.

Select an option

Save nkonev/6123537447722f3e81f7 to your computer and use it in GitHub Desktop.
@GrabConfig( systemClassLoader=true )
@Grapes(
@Grab(group='mysql', module='mysql-connector-java', version='5.1.26')
)
// create database groovy_mysql;
// create table words ( word_id BIGINT, spelling varchar(256), part_of_speech varchar(512), PRIMARY KEY(word_id));
// insert into words(word_id, spelling, part_of_speech) values (1, 'sam', 'bobcat');
import groovy.sql.Sql
class GroovySqlExample1{
static void main(String[] args) {
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/groovy_mysql", "root",
"1488", "com.mysql.jdbc.Driver")
sql.eachRow("select * from words"){ row ->
println row.word_id + " " + row.spelling + " " + row.part_of_speech
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment