• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What happens if Database Connections not closed?

 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a java application and Sql server database. In java application I am opening a database connection and not closing that DB connection. According to my understanding once we exit java application then all opened database connections from this application will be closed automatically. Is it not?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even if they are, do you really think that's a good idea?
 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not from my experience. Even after our application exited normally, we noticed several JDBC thin clients still connected to the Oracle DB. These were instances where developers overlooked closing connections, or failed to control for exceptions. I think the safe, simple rule to follow is: close all your connections explicitly.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yamini,

According to my understanding once we exit java application then all opened database connections from this application will be closed automatically


First of all, I agree with everyone who has said to close the connection. It is a good habit and important to do.

The connection being closed isn't tied to the application exiting though. It is tied to the database connection timeout. When a connection hasn't been used in a certain length of time, it can (sometimes) be recovered. The connection pool does not know whether the application has exited.
reply
    Bookmark Topic Watch Topic
  • New Topic