如何在Gradle任務中執行SQL?在Gradle任務中執行SQL?
configurations {
compile
}
repositories {
mavenCentral()
}
dependencies {
compile 'postgresql:postgresql:9.0-801.jdbc4'
}
task sql << {
driverName = 'org.postgresql.Driver'
Class.forName(driverName)
groovy.sql.Sql sql = Sql.newInstance(
'jdbc:postgresql://localhost:5432/postgres',
'username',
'password',
driverName
)
sql.execute 'create table test (id int not null)'
sql.execute 'insert into test (id) values(1)'
sql.eachRow 'select * from test' {
println it
}
}
我得到一個 拋出java.lang.ClassNotFoundException:org.postgresql.Driver執行SQL任務時例外。
見http://stackoverflow.com/questions/6329872/how-to-add-external-jar-文件到gradle-build-script用MySql作爲例子。 – thoredge
http://stackoverflow.com/questions/29010312/gradle-cannot-execute-sql-driver-not-found – yazabara