通过groovy执行sql
正在尝试使用查询插入行 如何使用groovy通过插入sql查询来协调目标系统通过groovy执行sql,groovy,oim,database-reconciliation,Groovy,Oim,Database Reconciliation,正在尝试使用查询插入行 如何使用groovy通过插入sql查询来协调目标系统 //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:
//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."
}
};
错误:
java.sql.SQLException:找不到适合jdbc的驱动程序:oracle:thin:@localhost:1521:orclsid
在grov.maingrov.groovy:25
问题是您试图使用Oracle JDBC驱动程序连接到数据库
def sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:orcl(sid)", "hr", "hr")
但是此驱动程序在您的类路径上不可用。如何将驱动程序添加到类路径取决于如何构建/运行应用程序。第二个问题不是问题。任何想法。。。谢谢。第一个问题在哪里?请将问题重新分段以使其更清楚。如何使指定的groovy脚本执行。。它给出了所提到的错误,并回答了我的第一个问题@JamesZWell。错误显然是你没有司机。你试着修好了吗?你有司机吗?您真的需要包括一些可以使用的东西,请看一看它有用于数据库连接调用的groovy脚本示例