0

Trying to insert a row using a query.

How to do reconcilation of target system using using groovy by inserting sql query?

//packages

import java.sql.*; 
import groovy.sql.Sql


// class

class test {

//main method


   static void main(String[] args) {

//Connection:

//def sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:orcl", "hr", "hr",
                          "oracle.jdbc.pool.OracleDataSource")

def sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:orcl(sid)", "hr", "hr")


   // insert new employee with Sql.executeInsert

def insertStr =
"""insert into Employee
   (COL1, COL2)
  values
   (COL1_seq.nextval, 'hai')"""
def insertedEmployees = sql.executeInsert(insertStr)
println insertedEmployees.dump()
def insertedEmployeeId = insertedEmployees[0][0].toJdbc()
println "TABLE_NAME ${insertedcol1} added."

   }

};

Error:

java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1521:orcl(sid) at grov.main(grov.groovy:25)

James Z
  • 12,209
  • 10
  • 24
  • 44
kumar
  • 15
  • 5
  • The 2nd question is not a question. "any ideas ... will be appreciated" and where's the 1st question? Please re-phase the question to make it more clear. – James Z Jul 12 '17 at 08:38
  • how to make the specified groovy script execte .. its giving the mentioned error and tats my 1st question @JamesZ – kumar Jul 12 '17 at 08:42
  • 1
    Well the error is clearly that you don't have a driver. Did you try to fix it? Do you have a driver? You really need to include something to work with – James Z Jul 12 '17 at 08:42
  • Take a look at the [OIM Generic Script Connector](https://docs.oracle.com/cd/E22999_01/doc.111/e69380/app_smpl_schema_example.htm#CACEFCDA) it has examples of groovy scripts for database connection calls – Berkley Lamb Jul 12 '17 at 20:29

1 Answers1

1

The problem is that you're trying to connect to the database using the Oracle JDBC driver

def sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:orcl(sid)", "hr", "hr")

But this driver isn't available on your classpath. Exactly how you add the driver to your classpath depends on how you build/run your application.

Dónal
  • 185,044
  • 174
  • 569
  • 824