GradleタスクでSQLを実行するにはどうすればよいですか? org.postgresql.Driver 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を取得します。
はhttp://stackoverflow.com/questions/6329872/how-to-add-external-jar-を参照してください。 MySqlを使用した例については、files-to-gradle-build-scriptを参照してください。 – thoredge
http://stackoverflow.com/questions/29010312/gradle-cannot-execute-sql-driver-not-found – yazabara