2
我得到下面的SQL異常,我不知道這個異常的根本原因是什麼?我也關閉數據庫連接和語句。java.sql.SQLException:ORA-00604:在遞歸SQL級別1發生錯誤
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注入攻擊。請閱讀[準備語句](http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html)來解決此問題。 – Ben
您粘貼的代碼似乎沒有任何遊標泄漏。我建議你在運行時檢查數據庫上的v $ open_cursor以確定發生了什麼。本的觀點也非常有效,th_id不應該只粘貼在那裏。如果你只在表格中尋找1行,不要只計算(*)至少要添加rownum = 1來減少你所做的工作。 – DazzaL
爲什麼在BEGIN和END中包含更新查詢?我認爲你的更新查詢是作爲一個PROCEDURE執行的,因爲你的while循環是無限的,導致了這個問題。 –