0

I am trying to connect to an Oracle Sql Developer DB using Groovys sql class, which requires 4 pieces of information: (db url, username, password, db driver) I have all information needed except the driver. I have tried using oracle.jdbc.driver.OracleDrive and have set my GROOVY_HOME as : Variable: %GROOVY_HOME%\lib Value: C:\Oracle_SQL_DEVELOPER\sqldeveloper

I am receiving the following error :

Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

I have referenced a few answers here on StackOverflow but haven't had any luck setting up a connection. Here are the links I've read and tried:

Unable to connect to oracle database from groovy

SQLException: No suitable Driver Found for jdbc:oracle:thin:@//localhost:1521/orcl

I have also looked and researched the Groovy documentation but it is not clear on how to define the driver: https://groovy-lang.org/databases.html#_connecting_with_a_datasource

Any help would be much appreciated. Here is the code for reference:

import groovy.sql.Sql

class EstablishConnection {

def static url = 'url'
def static user = 'user'
def static password = 'pass'
def static driver = 'oracle.jdbc.driver.OracleDriver'
def static sql = Sql.newInstance(url, user, password, driver)

}

EstablishConnection.sql.eachRow('select * from ACCOUNT where CONSTI_ID = \'12345678\';'){
        row ->
            def a = row[0]
    }
apg3253
  • 31
  • 5
  • oracle.jdbc.driver.OracleDrive First thing first - spelling. Missing an r at the end – Kaus2b Oct 24 '19 at 19:13
  • Thanks for that catch, I created the typo copying my code into the question. I am still getting the same issue. – apg3253 Oct 24 '19 at 19:19
  • do you have a jdbc jar installed? if so where? – Kaus2b Oct 24 '19 at 19:22
  • I dont have a jdbc jar installed as everything I read lead me to believe I only needed one if I was using a non oracle db..would I need a jdbc.jar regardless of db type? – apg3253 Oct 24 '19 at 19:27
  • I think you still need jdbc jar. Try putting these two lines at the top of your groovy file @GrabConfig(systemClassLoader=true) @Grab('com.oracle:ojdbc7:12.1.0.1.0') – Kaus2b Oct 24 '19 at 19:34
  • so I downloaded ojdbc jar version 7.1.8.0_111 and places C:\Oracle_SQL_Developer\sqldeveloper\lib and still no luck. Know if I actually need to create and define a %GROOVY_HOME% as a system variable? – apg3253 Oct 24 '19 at 19:56
  • did you try the Grab directives as I mentioned above? I was able to replicate your issue and in my case it works with those two lines at the top – Kaus2b Oct 24 '19 at 20:34
  • I figured this issue out. I had to add the below line of code to the build.Gradle file. // JDBC compile group: 'com.oracle.weblogic', name: 'ojdbc7', version: '12.1.3-0-0' – apg3253 Oct 24 '19 at 20:35

0 Answers0