繁体   English   中英

JDBC 中的 Pl/sql %RowType

[英]Pl/sql %RowType in JDBC

我一直在尝试执行 Oracle 存储过程,它使用 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)

简单的答案:使用JPublisher和 map 由 JPublisher 创建的类型,到 JDBC 连接类型映射。

The long answer: neither the JDBC specification nor the Oracle JDBC driver allows for custom (user-defined) types to be automagically converted into Java objects, and vice versa. 必须为此建立类型映射,以便驱动程序可以以适当的方式读取和写入连接。 While the Oracle JDBC driver does allow for certain SQL types to be read and written to, using the oracle.sql.* classes, it cannot be applied to UDTs, for the structure of the UDTs cannot be known in advance. 使用 JPublisher 解决了这个问题,因为它创建了反映 UDT 结构的类; 一旦 Oracle JDBC 驱动程序考虑了这些类,它就可以从结果集中读取适当的类型,或者可以将这些类型的对象写入连接 ZF7B44CFAFD5C52223D5498196C8A2E7.

我已经完成了与您所要求的类似的事情。 诀窍是声明行类型的引用并将返回声明为 cursor。 我在其他地方找到了相同的结果,希望对您有所帮助。

暂无
暂无

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

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