Skip to content

Instantly share code, notes, and snippets.

@xconnecting
Created November 29, 2012 01:25
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xconnecting/4166113 to your computer and use it in GitHub Desktop.
Save xconnecting/4166113 to your computer and use it in GitHub Desktop.
Gradle: Using jdbc in build script
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()
}
@igouss
Copy link

igouss commented Jul 29, 2021

Thank you.

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