In my program, I solved the ORA-01000 "Too many cursors open" problem by remembering the prepared statements and result sets, and closing them after I was sure they were no longer needed. This was not a new problem. It happened using ojdbc14.jar with
Java 5 and 6. I am now using JDK 6 update 6 (latest) with ojdbc6,jar on Oracle 10g R3.
Even though PreparedStatement may close when re-executed, I still had the problem, with at least
16 open cursors, and if there were uncommitted updates, there could have been be many more, and with other background activity on the database... (ours has max cursors set to 300)
I had many result sets that I could not close before they went out of scope. They were wrapped in table models and were frequently being replaced with a new result set. I had queries and updates, both using PreparedStatement's.
The solution was to save a reference to each statement or result set as it was created, in a Queue of mathcing type(ResultSet or PreparedStatement), and to iterate through the saved references, closing each one in turn. That appears to have eliminated the problem, and also improved performance.
For the update statements, I process the PreparedStatements queue, closing each one in turn immediately after commit. For the queries it's done just before I replace all 16 result sets. I used Doug Lea's
thread safe Queue in my Swing application.
[ April 27, 2008: Message edited by: Mike Rainville ]