简体   繁体   English

java.sql.SQLSyntaxErrorException:ORA-01722:refcursor上的resultSet.next()时数字无效,我不明白为什么?

[英]java.sql.SQLSyntaxErrorException: ORA-01722: invalid number while resultSet.next() on refcursor and I don't understand why?

I have an issue eating me for hours and I'm unable to find the exact reason why it is happening? 我有一个问题困扰着我好几个小时,而我却找不到确切的原因? I get java.sql.SQLSyntaxErrorException: ORA-01722: invalid number while iterating over refcursor out parameter of stored procedure using ResultSet.next(). 我得到java.sql.SQLSyntaxErrorException:ORA-01722:使用ResultSet.next()遍历存储过程的refcursor或out参数时无效的数字 What is bothering me is, it occurs even when there is actually no result to iterate over. 令我困扰的是,即使实际上没有结果可以迭代,它也会发生。

The signature of stored procedure: 存储过程的签名:

PROCEDURE GET_PROG_SRCH_BY_CRITERIA
       (p_orgID                  IN    NUMBER,
        p_MEPID                  IN    NUMBER,
        p_prog_prg_id            IN    NUMBER,
        p_pcom_enrol_date        IN    VARCHAR2,
        p_pcom_enrol_year_from   IN    VARCHAR2,
        p_pcom_enrol_year_to     IN    VARCHAR2,
        p_pcom_non_prtcm_date    IN    VARCHAR2,
        p_pcom_completion_date   IN    VARCHAR2,
        p_pcom_status_code       IN    VARCHAR2,        
        p_sys_cursor             OUT   SYS_REFCURSOR
       );

Java code snippet: Java代码段:

statement = connection.prepareCall("call PROG_TOOLS.GET_PROG_SRCH_BY_CRITERIA(?,?,?,?,?,?,?,?,?,?)");
statement.setLong(1, searchCriteria.getOrganizationID());
/*
 * Code to Set other 8 Parameters comes here
 */
statement.registerOutParameter(10, oracle.jdbc.OracleTypes.CURSOR);
statement.executeQuery();
resultSet = (ResultSet) statement.getObject(10);
/*
 * Code to Initialize necessary value Objects comes here
 */
while (resultSet.next()) {
    /*
     * Code to get values from resultSet using column named index
     * and initialize value objects
     * Few example:
     */
     dataVO = new DataVO();
     dataVO.setPcomID(result.getLong("PCOM_ID"));
     dataVO.setPersonID(result.getLong("PERSON_ID"));
     .
     .
     programList.add(dataVO);
}

Issue: If I call GET_PROG_SRCH_BY_CRITERIA by sending NULL in 3rd parameter, I get expected result. 问题:如果我通过在第3个参数中发送NULL来调用GET_PROG_SRCH_BY_CRITERIA,则会得到预期的结果。 If I call GET_PROG_SRCH_BY_CRITERIA by sending an actual value in 3rd parameter, I get java.sql.SQLSyntaxErrorException: ORA-01722: invalid number on the line 如果我通过在第3个参数中发送实际值来调用GET_PROG_SRCH_BY_CRITERIA,则会得到java.sql.SQLSyntaxErrorException:ORA-01722:该行上的数字无效

while (resultSet.next()) { while(resultSet.next()){

Exception trace: 异常跟踪:

java.sql.SQLSyntaxErrorException: ORA-01722: invalid number
    at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1030)
    at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:183)
    at oracle.jdbc.driver.T4CStatement.fetch(T4CStatement.java:1000)
    at oracle.jdbc.driver.OracleResultSetImpl.close_or_fetch_from_next(OracleResultSetImpl.java:314)
    at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:228)
    at weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl.next(Unknown Source)
    at org.app.ejb.program.dao.ProgDAO.searchProgEnrollees(ProgDAO.java:136)

I checked the procedure by testing it directly using SQLDeveloper tools by sending the same parameters which the above Java code used. 我通过发送与上述Java代码相同的参数,使用SQLDeveloper工具直接对其进行了测试,从而检查了该过程。 It worked absolutely fine. 它工作得很好。

I tried with OJDBC14 and OJDBC6 drivers, but no luck. 我尝试使用OJDBC14和OJDBC6驱动程序,但是没有运气。

I have no clue why this occurs on resultSet.next(). 我不知道为什么在resultSet.next()上发生这种情况。 If the 3rd parameter is null then I don't get this exception and flow works as expected. 如果第三个参数为null,则不会得到此异常,并且流程按预期进行。

Any help here is really appreciated. 非常感谢您的任何帮助。

Technologies used: - Java 6, ejb - Oracle 11g Database R2 (11.2.0.3) - Oracle Weblogic 10g (10.3.0) 使用的技术:-Java 6,ejb-Oracle 11g数据库R2(11.2.0.3)-Oracle Weblogic 10g(10.3.0)

Perhaps you need to call next() on the containing ResultSet first? 也许您需要首先在包含的ResultSet上调用next()?

statement.registerOutParameter(10, oracle.jdbc.OracleTypes.CURSOR);
ResultSet rs1 = statement.executeQuery();
rs1.next();
resultSet = (ResultSet) statement.getObject(10);

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

相关问题 错误 --> java.sql.SQLSyntaxErrorException: ORA-01722: 无效号码 - ERROR --> java.sql.SQLSyntaxErrorException: ORA-01722: invalid number java.sql.SQLSyntaxErrorException: ORA-01722 - java.sql.SQLSyntaxErrorException: ORA-01722 问题休眠(java.sql.SQLSyntaxErrorException:ORA-01722:无效的数字) - Issue hibernate (java.sql.SQLSyntaxErrorException: ORA-01722: invalid number) java.sql.SQLSyntaxErrorException:ORA-01722:number_where IN无效 - java.sql.SQLSyntaxErrorException: ORA-01722: invalid number_where IN 我无法理解 ORA-01722 背后的原因:无效号码 - I can't understand the reason behind ORA-01722: invalid number java.sql.SQLSyntaxErrorException-ORA-01722: 无效数字 - 准备好的语句 - java.sql.SQLSyntaxErrorException-ORA-01722: invalid number - Prepared statement 错误 java.sql.SQLException: ORA-01722: 运行准备好的语句以更改序列时数字无效 - ERROR java.sql.SQLException: ORA-01722: invalid number while running a Prepared Statement to alter a Sequence 在准备语句中执行 IN 子句时出现无效数字异常(ORA-01722) - invalid number exception(ORA-01722) while executing IN clause in preparedstatement java.sql.SQLSyntaxErrorException:ORA-00911:无效字符 - java.sql.SQLSyntaxErrorException: ORA-00911: invalid character java.sql.SQLSyntaxErrorException:ORA-00903:表名无效 - java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM