[英]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.