Grails 3无法解析类oracle.sql

时间:2017-05-07 15:30:30

标签: oracle grails jdbc grails3

尝试运行具有jdbc6依赖关系的grails 3应用程序。我正在尝试在我的groovy服务中导入以下库,该服务应该连接到Oracle数据库以调用存储过程。

import oracle.sql.ARRAY
import oracle.sql.ArrayDescriptor
import oracle.jdbc.OracleCallableStatement
import java.sql.Connection
import groovy.sql.Sql

import org.apache.poi.ss.usermodel.Workbook
import org.apache.poi.ss.usermodel.WorkbookFactory
import org.apache.poi.ss.usermodel.Sheet
import org.apache.poi.ss.usermodel.Cell
import org.apache.poi.ss.usermodel.Row
import org.apache.poi.ss.usermodel.DataFormatter
import com.wwt.itemuploadapi.rectypes.Rectype

import java.sql.SQLException

class ExcelService {

def dataSource

private static final FILE_HEADERS = [
        'First Name': 'firstName',
        'Last Name': 'lastName'
]

def callApi(List<Rectype> rectype) {

    OracleCallableStatement callableStmt = null

    try {
        def conn = dataSource.getConnection()
        ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("TBLTYPE", conn.unwrap(oracle.jdbc.OracleConnection.class))
        ARRAY dataElementsArray = new ARRAY(descriptor, conn.unwrap(oracle.jdbc.OracleConnection.class), (Object[])rectype.toArray())
        Map map = conn.getTypeMap()
        map.put("REC_TYPE", Rectype.class)
        callableStmt = (OracleCallableStatement)conn.prepareCall("{call package.procedure_name(?)}")
        callableStmt.setArray(1, dataElementsArray);

        callableStmt.execute()
    }
    catch (SQLException ex) {
        println(ex)
    }
}

启动时我得到以下三个错误。但我在Gradle: com.oracle:ojdbc6:11.2.0.3库下有这些类。所以我不确定为什么它不能识别它们。

 `unable to resolve class oracle.sql.ARRAY`
 `unable to resolve class oracle.sql.ArrayDescriptor`
 `unable to resolve class oracle.jdbc.OracleCallableStatement`

为什么无法找到这些课程的任何建议?

1 个答案:

答案 0 :(得分:0)

oracle.jdbc.OracleCallableStatement 

不再是您正在使用的ojdbc依赖版本的正确类。

应该更新到此导入和类:

import java.sql.CallableStatement
CallableStatement callableStmt = null

这是一个链接,它会告诉您需要做什么来替换您尝试使用的其他已弃用的类(oracle.sql.ARRAYoracle.sql.ArrayDescriptor): https://docs.oracle.com/database/121/JAJDB/deprecated-list.html#class