Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how is close() used?

 
Stephan Ort
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i'm wondering how the close() method is used exactly.

which one is correct, when you want to make two queries?:

1)


2)


3)


which of these make all of the possible closings, or does none?

are there easier ways to use one Statement objects for more than one query although all possible closings are done? Is this even possible?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
None. You should be closing the result set before the statement.
 
Stephan Ort
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, so it would be:

 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Now you are closing the resultset before you finished using it.
Jeanne was saying that you should close the resultset before closing the statement.

We advise you to close the jdbc resources in a finally block.
 
Vijayakumar Rengaraj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In between the two DB interactions you can close the resultset but not the statement object .

But it is not advisable to close the resultset and statement objects within try block.
you can try the below code:

finally{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
}
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should close the resultset before closing the statement object relating it.

must make sure that you are done manipulating the resultset before closing it.

 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Vijayakumar!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic