Access a oracle db runs no more with Gradle 1.0-rc-3


(dorin.dragan-sassler) #1

I have a groovy project with following build.gradle:

apply plugin: ‘groovy’

repositories {

maven {

name ‘nexus-central’

url ‘…’

}

maven {

name ‘local-repo’

url ‘file:///C:/.maven-rep/’

} }

dependencies {

runtime “com.oracle:ojdbc6:11.2.0.2.0” }

URLClassLoader loader = GroovyObject.class.classLoader configurations.runtime.each { File file ->

loader.addURL(file.toURL()) }

task dbSelect << {

try {

sql = new groovy.sql.Sql(java.sql.DriverManager.getConnection(“jdbc:oracle:thin:@dbserver:11111:alias”, “SCHEMA”, “PWD”))

sql.eachRow(“select 1 from dual”) {

println “$it”

}

}

catch(e) {

if (e.getMessage().indexOf(“ORA-00942: Tabelle oder View nicht vorhanden”) == 0) {

logger.warn(“Database empty.”)

}

else { throw e

}

} }

dbSelect runs on Gradle 1.0-milestone-7. Output: :dbSelect [1:1] I installed the new Gradle 1.0-rc-3 and my task runs no more. I get the following message: Execution failed for task ‘:dbSelect’. > java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@dbserver:11111:alias

Can you tell me what is the problem and the solution?

Many Thanks, Dragan-Sassler


(Peter Niederwieser) #2

Have you tried to put the Oracle driver on the buildscript class path? Something like:

buildscript {
  repositories { ... }
  dependencies {
     classpath "com.oracle:ojdbc6:11.2.0.2.0"
   }
}

(dorin.dragan-sassler) #3

I have tryed, but no luck. buildscript {

repositories {

maven {

name ‘local-repo’

url ‘file:///C:/.maven-rep/’

}

}

dependencies {

classpath “com.oracle:ojdbc6:11.2.0.2.0”

} }


(Peter Niederwieser) #4

The following works fine for me with 1.0-rc-3:

import groovy.sql.Sql
  repositories {
    mavenCentral()
}
  configurations {
    h2database
}
  dependencies {
    h2database "com.h2database:h2:1.3.166"
}
  configurations.h2database.each {
  GroovyObject.class.classLoader.addURL(it.toURI().toURL())
 }
  task useDatabase << {
    def sql = Sql.newInstance("jdbc:h2:mem:", "org.h2.Driver")
    try {
        sql.execute("create table maxdata (id int primary key, a int, b int, c int)")
        sql.execute("insert into maxdata values (1, 3, 7, 7), (2, 5, 4, 5), (3, 9, 9, 9)")
        println sql.rows("select a, b, c from maxdata")
        } finally {
        sql.close()
    }
}

(dorin.dragan-sassler) #5

Hello Peter,

it don’t works for me: the same error java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@s0660021.vz.ba.de:56321:evamdb1

Additional informations: I stoped the daemons for 1.0-milestone-7 and rc3, deleted chaches and daemon folders “logger.info loader.getURLs().toString()” makes an output with all jars from C:/Programme/gradle-1.0-rc-3/lib/ and in addition file:/C:/.maven-rep/com/oracle/ojdbc6/11.2.0.2.0/ojdbc6-11.2.0.2.0.jar

My environment (winXP) is: ANT_HOME=C:\Programme\apache-ant-1.8.1 GRADLE_HOME=C:\Programme\gradle-1.0-rc-3 GRADLE_OPTS=-Dorg.gradle.daemon=true GRADLE_USER_HOME=C:\eclipse\gradleUserHome GROOVY_HOME=C:\Programme\groovy-1.8.6 JAVA_HOME=C:\Programme\Java\jdk1.6.0_32 M2_HOME=C:\Programme\apache-maven-3.0 Path=C:\Programme\gradle-1.0-rc-3\bin;C:\Programme\apache-maven-3.0\bin;C:\Programme\apache-ant-1.8.1\bin;C:\Programme\Java\jdk1.6.0_32\bin;…

Best regards, Dorin


(Peter Niederwieser) #6

It’s hard for me to say what the problem is. JDBC class loading is tricky, and with Groovy in the mix it becomes even trickier. You could try to write a Java class that does the database work, put it into ‘buildSrc’, and use it from the build script. See the user guide for more information on ‘buildSrc’.


(dorin.dragan-sassler) #7
def driverClass = Class.forName("oracle.jdbc.OracleDriver")

before create connection solved my problem.