I use loops in my java code to insert rows into my database. Then, I got the error -
ORA-01000: maximum open cursors exceeded
I searched a little and saw that closing my prepared statements or statements after adding each row helps to get rid of the error.
But, I need to understand -
- what are cursors ?
- Can i change the number of cursors ? If yes, is it a good thing to do ?
This link will will explain you what a cursor is and how it works.
Yes you can change the maximum number of cursors on Oracle using the following statement:
ALTER SYSTEM SET OPEN_CURSORS=1337 SID='*' SCOPE=BOTH;But you should do that just if really needed. What you really should do is handle resultset and statements correctly, and ensure that you always close them. This should typically be done in a
try/finallystatement.If you forget to close these, open cursors will leak until you reach the maximum limit (which comes very quickly), and subsequent requests won't work (this is the case for you).
You could edit your question and add some code so that we can show you some hint about how and where your may close the resultset and statement properly.
This is typical usage:
It is the same with resultset. Depending on the version of Java you're using you could use the try-with-resources idiom.
Java will take care of closing the statement at the end of the
tryblock, since Statement implements theAutoCloseableinterface.