如果在 EJB 中抛出异常,如何处理游标

How to handle cursor if it throws exception in EJBs

我有一个 callableStatment,执行时出现以下错误

    try{
callableStatement.executeQuery()
}
    catch (Throwable t) {
                throw new Exception(t);

            } 
            finally {
                closeResultSet(rs);
                closeCallableStatement(callableStatement);
                closeConnection(dbConnection);

            }
javax.ejb.EJBTransactionRolledbackException: ORA-30926: unable to get a stable set of rows in the source tables

一段时间后,我得到 "Too man open cursors"

的数据库错误

我知道程序由于重复而抛出错误,我想知道为什么 Cursors 没有关闭,因为它似乎最终块没有做我需要的事情以及关闭它们的正确方法是什么

executeQuery() 的 return 类型是您未指定的 ResultSet。尝试将其作为

ResultSet rst = callableStatement.executeQuery();

希望对您有所帮助。 :)

我认为您正在执行合并查询并且返回了不止 1 个行 ID。这就是该例外的原因。同样,当返回第一个重复行时,本身就会抛出异常。在查询甚至执行之前,您正试图关闭它。这应该是游标没有正确关闭的原因。尝试在查询中添加不同的关键字以避免重复。例如:MERGE INTO table_1 a USING (SELECT distinct ta.ROWID row_id FROM table_1 a ,table_2 b ,table_3 c WHERE ) src ON ( a.ROWID = src.row_id ) WHEN MATCHED THEN ;由于涉及到回滚,它属于系统异常。并且应用程序异常不会回滚。