Created
March 15, 2015 13:20
-
-
Save grimrose/b08bbc570d0e27630bc0 to your computer and use it in GitHub Desktop.
#yokohamagroovy #30
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
buildscript { | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
classpath 'org.apache.derby:derby:10.11.1.1' | |
} | |
} | |
def loader = GroovyObject.class.classLoader | |
buildscript.configurations.classpath.each { f -> loader.addURL(f.toURL()) } | |
import groovy.sql.* | |
task groovySqlWithDerby << { | |
String url = 'jdbc:derby:memory:testdb;create=true' | |
String user = 'user' | |
String pass = 'password' | |
String driver = 'org.apache.derby.jdbc.EmbeddedDriver' | |
def db = Sql.newInstance(url, user, pass, driver) | |
db.execute('''create table person ( | |
id integer not null primary key, | |
firstname varchar(20), | |
lastname varchar(20), | |
location_id integer, | |
location_name varchar(30) | |
)''') | |
def person = [id: 1, first: 'abc', last: 'xyz', locId: 10, locName: 'Yokohama'] | |
db.execute(""" | |
insert into person (id, firstname, lastname, location_id, location_name) | |
values (${person.id}, ${person.first}, ${person.last}, ${person.locId}, ${person.locName}) | |
""") | |
db.dataSet('person').each { println it } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment