File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why we want close connection ?.

 
Praveen Kumar
Ranch Hand
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1294
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33684
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Server can manage this things automatically .For example Timeout (Minutes) in BEA WebLogic
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 528
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bauke
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic