aspose file tools
The moose likes JDBC and the fly likes What happens if Database Connections not closed? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "What happens if Database Connections not closed?" Watch "What happens if Database Connections not closed?" New topic
Author

What happens if Database Connections not closed?

yamini nadella
Ranch Hand

Joined: Apr 13, 2004
Posts: 257
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

Joined: Jan 10, 2002
Posts: 56185
    
  13

Even if they are, do you really think that's a good idea?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Jeffrey Hunter
Ranch Hand

Joined: Apr 16, 2004
Posts: 305
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 26183
    
  66

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.


[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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: What happens if Database Connections not closed?
 
Similar Threads
Closing database connections properly?
Connection Pooling in Tomcat
closing the database connection
Connection Pooling
DataSource.getConnection() returning closed connections