我有一个复杂的 PL/SQL 存储函数,我必须在 JAVA 中调用这个函数。这是程序:
FUNCTION SUB_REPORT_INCOMPLETE(p_ACT_ID IN ACTIVITIES.ID%TYPE,
p_MISSING TO_SUB_MISSING) RETURN VARCHAR2;
因此,正如您在此处看到的,我的第二个参数的类型是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);
经过一些研究,我写了这段代码:
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();
但是使用此代码,我在StructDescriptor.createDescriptor行上遇到异常:
java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection
我尝试使用在一些stackoverflow帖子上找到的两种解决方案来解决此异常,但它没有用。
解决方案 1:
OracleConnection oraConn = (OracleConnection) new DelegatingConnection(connection).getInnermostDelegate();
解决方案 2:
OracleConnection oraConn = connection.unwrap(OracleConnection.class);
第一个解决方案抛出相同的异常,第二个抛出以下异常:
java.lang.AbstractMethodError: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.unwrap(Ljava/lang/Class;)Ljava/lang/Object;
您知道如何解决我的问题吗?