I am trying to query a db from within a gradle script task. I started with a groovy script to verify the code
import groovy.sql.Sql
this.class.classLoader.rootLoader.addURL(new URL('file:<..>/jtds-1.2.2.jar'))
def driver = 'net.sourceforge.jtds.jdbc.Driver'
def dburl = "jdbc:jtds:sqlserver://ITSVIL:1433/APPDB"
def first
Sql.withInstance(dburl, '<..>', '<..>', driver) {
sql ->
first = sql.firstRow( "SELECT * FROM PROJECT" )
}
I launched with groovy QueryTest.groovy and verified that it worked. Then I moved the script within a gradle task, no changes on code but loading handled by gradle buildscript statement
import groovy.sql.Sql
defaultTasks 'queryTest'
buildscript {
dependencies {
classpath files('<..>/jtds-1.2.2.jar')
}
}
task queryTest () {
// l'update va su REPOSITORYURL + '/' + alm.project.vcrProjectName + '/' + Reference
doLast {
def driver = 'net.sourceforge.jtds.jdbc.Driver'
def dburl = "jdbc:jtds:sqlserver://ITSVIL:1433/APPDB"
def first
Sql.withInstance(dburl, '<..>', '<..>', driver) {
sql ->
first = sql.firstRow( "SELECT * FROM PROJECT" )
}
}
}
Launched with gradle -b QueryTest.gradle, this time I am getting
Execution failed for task ':queryTest'.
> java.sql.SQLException: No suitable driver found for jdbc:jtds:sqlserver://ITSVIL:1433/IKALM_APP
Tried any possible advice I found in forums without success. Would ask for help.