Created
November 29, 2012 01:25
-
-
Save xconnecting/4166113 to your computer and use it in GitHub Desktop.
Gradle: Using jdbc in build script
This file contains 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
import groovy.sql.Sql | |
apply plugin: 'groovy' | |
apply plugin: 'eclipse' | |
apply plugin: 'maven' | |
repositories { mavenCentral() } | |
configurations { driver } | |
dependencies { driver 'org.xerial:sqlite-jdbc:3.7.2' } | |
URLClassLoader loader = GroovyObject.class.classLoader | |
configurations.driver.each {File file -> | |
loader.addURL(file.toURL()) | |
} | |
task jdbcSample << { | |
def sql = Sql.newInstance( 'jdbc:sqlite:test.db' | |
, '' | |
, '' | |
, 'org.sqlite.JDBC' ) | |
sql.execute '''\ | |
CREATE TABLE IF NOT EXISTS person( | |
id int primary key | |
,name varchar | |
) | |
''' | |
sql.execute '''\ | |
INSERT OR IGNORE INTO person VALUES( | |
1 | |
,'test' | |
) | |
''' | |
sql.eachRow( 'select * from person' ) { | |
int id = it.id | |
println "id:$id name:$it.name" | |
} | |
sql.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you.