This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
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.