简体   繁体   中英

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. 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 :

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 :

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.

Solution 1 :

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

Solution 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可能这将帮助您解决您的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM