sql execution through groovy

814 views Asked by At

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)

1

There are 1 answers

0
Dónal On

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.