Reputation: 4574
I am facing ORA-01000: maximum open cursors exceeded although I am closing the resultsets in finally block. But I suspect there is some trouble with my legacy code, below is my pseudo-code
while (someCondition) {
rs1=executePreparedStatementNew(query1,param1,"");
//do something with rs1
rs1=executePreparedStatementNew(query2,param2,"");
}
Appreciate any help.
Upvotes: 2
Views: 545
Reputation: 1500225
You haven't said where your finally block is, but if it's outside the while loop, then yes you will have unclosed result sets. The rs1
variable will refer to the "latest" result set fetched - so that's the only one which will be closed. There's nothing magical going on here - it's just the normal behaviour of variables.
I would suggest that you separate each "fetch result set and use it" case into its own method, and close the result set in a try/finally block within that method. That will make it fairly clear what's going on.
Upvotes: 6