Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Statement and PreparedStatemnet---ORA-01000

 
sreedhar lak
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am facing one problem in my application only some times.
The problem description shows it is regarding cursors opened (ORA-01000).
Please see the code below...
closeDBStuff(Connection con, Statement pStmt, ResultSet rs){

if (rs != null)
rs.close();
if (pStmt != null)
pStmt.close();
if (con != null)
con.close();
con=null;
rs=null;
pStmt=null;
}
I am calling this method from all my methods from a finally{} only.
My doubt is: Suppose if i created an object/ref to PreparedStatement in one method and in that finally i am calling closeDBStuff() method by passing this PS ,it is not giving any error even this closeDBStuff() is expecting Statement obj.but my doubt is whether it is really closing that obj.
Please help me in this regard...
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is closing it, but it is not "dereferencing" the original variable that was passed in using the "= null" statements at the end of the method. The original variables will still reference the objects they referenced before the method call, because Java passes all parameters by value, it is just that the passed value of a reference will still refer to the same object, but is still only a copy of the original reference, so, reassigning this reference variable to null in the method will still leave the original reference untouched.
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sreedhar lak:

My doubt is: Suppose if i created an object/ref to PreparedStatement in one method and in that finally i am calling closeDBStuff() method by passing this PS ,it is not giving any error even this closeDBStuff() is expecting Statement obj.but my doubt is whether it is really closing that obj.
Please help me in this regard...


PreparedStatement is a sub-class of Statement, so you can correctly use a PreparedStatement object (or a CallableStatement object) when you call closeDBStuff().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic