It's not a secret anymore!*
The moose likes JDBC and the fly likes Why we want close connection ?. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Why we want close connection ?." Watch "Why we want close connection ?." New topic
Author

Why we want close connection ?.

Praveen Kumar
Ranch Hand

Joined: Nov 06, 2006
Posts: 133
Hi ,

Once we performed all JDBC calls to DB, We will close the connection right.

If you did not, JVM automatically close the connection which are opened and releases JDBC resourses.

Any way JVM will take of Connections right.

Please help me out.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi Praveen,

it's always better to close connections immediately if you know you don't need them anymore. I can imagine that it depends on the JDBC implementation if connections are closed correctly when you shutdown an application. If they're not closed correctly they may still appear as opened on the server side and so eating up resources and locking out other database clients waiting for free connections!

Marco
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31062
    
232

Originally posted by Praveen Kumar:
Any way JVM will take of Connections right.

Eventually. In the meantime, your application might hang causing you to kill the JVM and the connections being in use until they timeout.


[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
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
The Server can manage this things automatically .For example Timeout (Minutes) in BEA WebLogic


If you want something you never had do something which you had never done
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The JVM does completely nothing with the connection. You've it in your own hands. Always acquire and close them in the shortest possible scope. To improve performance, just introduce connection pooiling. This does still not mean that you change the way of opening/closing connections in your JDBC code.
RaviNada Kiran wrote:The Server can manage this things automatically .For example Timeout (Minutes) in BEA WebLogic
It's called 'connection pooling'. That's not something magical. You still have to write your JDBC code so that you close connections and other resources the right way. Otherwise it will still run out of connections sooner or later.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Thanks Bauke
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why we want close connection ?.