简体   繁体   中英

Pl/sql %RowType in JDBC

I have been trying to execute a Oracle Stored procedure which returns %ROWTYPE using JDBC, as i mentioned below

  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: that we are getting is as follows

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)

The simple answer: use JPublisher , and map the types created by JPublisher, to the JDBC Connection type mapping.

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. A type mapping must be established for this, so that the driver can read and write to the connection in an appropriate manner. 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. Using JPublisher resolves this problem for it creates classes that reflect the structure of the UDT; once these classes are taken into consideration by the Oracle JDBC driver, it can read the appropriate types from the result set, or may write objects of these types into the connection stream.

I've done something similar to what you're asking. The trick there was to declare a refcursor of the rowtype and declare the return as a cursor. I've found the same result elsewhere, hope it helps you.

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