wood burning stoves 2.0*
The moose likes JDBC and the fly likes Change of statements! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Change of statements!" Watch "Change of statements!" New topic
Author

Change of statements!

manjit singh thakurratan
Greenhorn

Joined: Dec 23, 2009
Posts: 10
Hi

The sequence for closing connections in a jdbc driven program is

ResultSet.close
Statement.close
Connection.close

What might be the consequences if I close the connection first!? ??

Thnx
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30369
    
150

Manjit,
Welcome to JavaRanch!

If you close the connection first, the statement and result set are invalid. They may or may not get closed depending on your driver. They may or may not throw an exception when you try to close them; also depending on your driver. I advise you not to code that way as the results can be unpredictable.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Change of statements!