• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What happens if Database Connections not closed?

 
yamini nadella
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if they are, do you really think that's a good idea?
 
Jeffrey Hunter
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34695
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic