【发布时间】:2012-11-06 10:43:22
【问题描述】:
我收到以下 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();
}
【问题讨论】:
-
您容易受到 SQL 注入的攻击。请阅读prepared statements 来解决此问题。
-
您粘贴的代码似乎没有任何光标泄漏。我建议您在运行时检查数据库上的 v$open_cursor 以确定发生了什么。本的观点也很有效, th_id 不应该只是粘贴在那里。另外,如果您只在表中查找 1 行,请不要仅 count(*) 至少添加 where rownum = 1 以减少您所做的工作。
-
为什么您的更新查询包含在 BEGIN 和 END 中?我认为您的更新查询正在作为 PROCEDURE 执行,并且由于您的 while 循环是无限的,因此会导致问题。