我一直在尝试执行Oracle Stored过程,该过程使用JDBC返回%ROWTYPE,如下所述
OracleCallableStatement ocs = (OracleCallableStatement)conn.prepareCall("begin <PackageName>.procedureName(?,?,?,?); end; ");
ocs.setString(1, "001");
ocs.registerOutParameter(2,java.sql.Types.VARCHAR);
ocs.registerOutParameter(3,java.sql.Types.VARCHAR);
***ocs.registerOutParameter(4,java.sql.Types.OTHER);*** /*here What do i need to put, i didn't find Wrapperclass which is compatible for %ROWTYPE*/
ocs.executeUpdate();
String newerrorcode = ocs.getString(2);
System.out.println("\n ErrorCode = " + newerrorcode );
String newErrorDesc = ocs.getString(3);
System.out.println("\n ErrorDesc = " + newErrorDesc );
ResultSet rs = (ResultSet) ocs.getObject(4);
例外:我们得到的如下
Exception in thread "main" java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PR_APP_DATE'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:202)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1005)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3530)
at oracle.jdbc.driver.OracleCallableStatement.executeUpdate(OracleCallableStatement.java:4735)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at testSysBusinessDts.main(testSysBusinessDts.java:62)
答案 0 :(得分:2)
简单的答案:使用JPublisher,并将JPublisher创建的类型映射到JDBC连接类型映射。
答案很长:JDBC规范和Oracle JDBC驱动程序都不允许自定义(用户定义)类型自动转换为Java对象,反之亦然。必须为此建立类型映射,以便驱动程序可以以适当的方式读取和写入连接。虽然Oracle JDBC驱动程序允许使用oracle.sql.*
类读取和写入某些SQL类型,但它不能应用于UDT,因为UDT的结构无法事先知道。使用JPublisher解决了这个问题,因为它创建了反映UDT结构的类;一旦Oracle JDBC驱动程序考虑了这些类,它就可以从结果集中读取相应的类型,或者可以将这些类型的对象写入连接流。
答案 1 :(得分:1)
我做了类似于你问的事情。诀窍是声明rowtype的refcursor并将return声明为游标。 I've found the same result elsewhere, hope it helps you.