java.sql.SQLException:ORA-00604:递归sql级别1发生错误

java.sql.SQLException:ORA-00604:递归sql级别1发生错误,java,oracle,jdbc,Java,Oracle,Jdbc,我得到下面的SQL异常,我不知道这个异常的根本原因是什么?我也正在关闭数据库连接和语句 java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1 ORA-01000: maximum open cursors exceeded ORA-00604: error occurred at recursive SQL level 1 ORA-01000: maximum open cursors exceeded

我得到下面的SQL异常,我不知道这个异常的根本原因是什么?我也正在关闭数据库连接和语句

java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
ORA-01000: maximum open cursors exceeded
ORA-00604: error occurred at recursive SQL level 1
ORA-01000: maximum open cursors exceeded
ORA-01000: maximum open cursors exceeded
以下是我的代码:

 while(true)
 {

   Statement stmt2 = conn1.createStatement();
   ResultSet rs2 = null;

   int rec_count=0;
   rs2 = stmt2.executeQuery("select count(*) as cnt from   some_table");                                  
    while(rs2.next())
   {
     rec_count = rs2.getInt("cnt");
   }

   if(rec_count>0)
   {
     update_qry_b_trg1 = "update some_table set to_be_triggered=1,algo_status='D',dealer_id='HD001',price_trig_date=sysdate where buy_sell = 'SELL' and ordertype = 'BNLD' and to_be_triggered = 0 and algo_status = 'P' and Mod(group_ref_no,5)="+th_id;

   String final_qry = "BEGIN \n"+update_qry_b_trg1+";\n"+";\n END;";

   int rows = stmt1.executeUpdate(final_qry);
   stmt1.close();
   }

   rs2.close();
   stmt2.close();

   }

无论何时初始化stmt1,最好在finally块中关闭它。在您的情况下,您是在if条件下关闭它。如果条件没有通过,语句将保持打开状态,您将得到以下结果

java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1

此外,您还可以在while循环中运行该语句,因此您需要确保关闭每个打开的语句。

您很容易受到SQL注入的攻击。请阅读有关修复此问题的内容。您粘贴的代码似乎没有任何光标泄漏。我建议您在运行数据库时检查数据库上的v$open\u游标,以确定发生了什么。本的观点也很有道理,不应该只是贴在上面。另外,如果您只查找表中的1行,请不要只计算(*),至少添加where rownum=1以减少您所做的工作。为什么您的更新查询包装在BEGIN和END中?我认为您的更新查询是作为一个过程执行的,因为您的while循环是无限的,这就是问题的根源。