Created
October 9, 2015 23:24
-
-
Save nkonev/6123537447722f3e81f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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