Come posso eseguire SQL in un'attività Gradle?Esecuzione di SQL in un'attività Gradle?
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
}
}
ottengo un java.lang.ClassNotFoundException: org.postgresql.Driver un'eccezione durante l'esecuzione del compito di sql.
Vedi http://stackoverflow.com/questions/6329872/how-to-add-external-jar- files-to-gradle-build-script per un esempio con MySql. – thoredge
http://stackoverflow.com/questions/29010312/gradle-cannot-execute-sql-driver-not-found – yazabara