简体   繁体   English

JDBC调用Oracle存储函数 - 类型为“struct of struct”的IN参数

[英]JDBC Call to Oracle Stored Function - IN parameter of type “table of struct”

I have a complex PL/SQL stored function and I have to call this function in JAVA. 我有一个复杂的PL / SQL存储函数,我必须在JAVA中调用此函数。 Here is the procedure : 这是程序:

FUNCTION SUB_REPORT_INCOMPLETE(p_ACT_ID IN ACTIVITIES.ID%TYPE,
                               p_MISSING TO_SUB_MISSING) RETURN VARCHAR2;

So, as you can see here, the type of my second parameter is TO_SUB_MISSING which is a table of O_SUB_MISSING : 所以,正如你在这里看到的,我的第二个参数的类型是TO_SUB_MISSING ,它是一个O_SUB_MISSING表:

CREATE OR REPLACE TYPE TO_SUB_MISSING AS TABLE OF O_SUB_MISSING;
CREATE OR REPLACE TYPE O_SUB_MISSING AS OBJECT (ACT_ID NUMBER, GIT_ID NUMBER, MISSING_QTY NUMBER);

After some researchs, I write this code : 经过一些研究,我写了这段代码:

Context context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup(dataSourceName);
connection = dataSource.getConnection();

StructDescriptor structDescriptor = StructDescriptor.createDescriptor("O_SUB_MISSING", connection);
STRUCT[] structs = new STRUCT[listPieces.size()];
int ind = 0;
for (PieceEntity piece : listPieces) {
    Object[] params = new Object[3];
    params[0] = piece.getActId();
    params[1] = piece.getGitId();
    params[2] = piece.getMissingQty();
    STRUCT struct = new STRUCT(structDescriptor, connection, params);
    structs[ind++] = struct;
}
ArrayDescriptor desc = ArrayDescriptor.createDescriptor("TO_SUB_MISSING", connection);

statement = connection.prepareCall(Constants.DECLARE_INCOMPLETE_MODUL);
statement.registerOutParameter(1, OracleTypes.VARCHAR);
statement.setLong(2, agmId);
statement.setArray(3, new ARRAY(desc, connection, structs));
statement.executeQuery();

But with this code I get an exception on the StructDescriptor.createDescriptor line : 但是使用这段代码,我在StructDescriptor.createDescriptor行上得到了一个异常:

java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection

I try to solve this exception with two solutions I find on some stackoverflow post but it didn't work. 我尝试使用我在某些stackoverflow帖子上找到的两个解决方案来解决此异常,但它不起作用。

Solution 1 : 解决方案1:

    OracleConnection oraConn = (OracleConnection) new DelegatingConnection(connection).getInnermostDelegate();

Solution 2 : 解决方案2:

    OracleConnection oraConn = connection.unwrap(OracleConnection.class);

The first solution throw the same exception and the second throw the following exception : 第一个解决方案抛出相同的异常,第二个抛出以下异常:

java.lang.AbstractMethodError: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.unwrap(Ljava/lang/Class;)Ljava/lang/Object;

Have you an idea of how I can solve my issue ? 您知道我如何解决我的问题吗?

不是具体的解决方案,但它是一个提示: https//community.oracle.com/thread/718072? tstart = 832可能这将帮助您解决您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用PL SQL表类型的参数对Oracle存储过程进行JDBC调用 - JDBC Call to Oracle Stored Procedure with parameters of type PL SQL table 表类型的调用过程。 创建结构时发生异常:java.lang.AbstractMethodError:oracle.jdbc.driver.T4CConnection.createStruct - Call procedure with a table type. Exception while create Struct: java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.createStruct Oracle 11g:使用简单的 jdbc 调用将数组作为输入参数传递给 oracle 存储过程 - Oracle 11g: Pass array as input parameter to an oracle stored procedure using simple jdbc call 不带参数从Java调用oracle存储函数 - call oracle stored function from java taking no parameter 如何使用Java调用Oracle数据库中IN和OUT参数的存储函数 - how to call stored function of IN and OUT parameter in Oracle Database using Java 使用简单的jdbc调用将数组作为输入参数传递给oracle存储过程 - Pass array as input parameter to an oracle stored procedure using simple jdbc call 使用简单的jdbc调用将数组作为输入参数传递给oracle存储过程 - Pass array as input parameter to an oracle stored procedure using simple jdbc call 如何使用JDBC / Spring调用Oracle存储过程,其中一些参数类型是用户定义的? - How can I call an Oracle stored procedure with JDBC/Spring where some of the parameter types are user defined? JDBC取消Oracle存储过程调用 - JDBC cancel Oracle stored procedure call 使用 VARRAY 或用户定义类型作为 IN 参数的 Oracle 存储函数/过程 - Oracle stored function/procedure with VARRAY or user-defined type as IN parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM