Search code examples
oracle-databasegroovyoracle11gojdbc

groovy oracle - No suitable driver found


Groovy 2.4.12
Oracle Express 11.2.0.2
ojdbc6.jar

I've just installed Oracle Express created a new user with all privileges. I can connect to my xe instance from SQL Developer, so I know its running.

Groovy console, I've added ojdbc6.jar to the classpath and now trying this...

import groovy.sql.Sql;

def cl = Class.forName('oracle.jdbc.OracleDriver')
println cl // outputs 'class oracle.jdbc.OracleDriver'

def db = [
 url: 'jdbc:oracle:thin:@localhost:1521:xe',
 user: 'me',
 password: 'me', 
 driver: 'oracle.jdbc.OracleDriver']
def sql = Sql.newInstance(db.url, db.user, db.password, db.driver)

I get the SQLException "No suitable driver found for jdbc:oracle:thin:@//localhost:1521/xe".

For the connect string I've also tried jdbc:oracle:thin:@localhost:1521:xe and I've also tried oracle.jdbc.driver.OracleDriver for both loading and the driver parameter.

Is this combo not possible or have I missed something obvious?

EDIT:

Correct connect string is the no-slashes format.


Solution

  • Turns out @tim_yates was almost there.

    Needed this...

    def f = new File('c:\\oraclexe\\app\\oracle\\product\\11.2.0\\server\\jdbc\\lib\\ojdbc6.jar')
    this.getClass().classLoader.rootLoader.addURL(f.toURL())
    

    No idea why MySQL worked without this!