wood burning stoves 2.0*
The moose likes JDBC and the fly likes about datasource close? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "about datasource close?" Watch "about datasource close?" New topic
Author

about datasource close?

daming wang
Greenhorn

Joined: Jul 28, 2004
Posts: 27
hi all,
I have a question about close the datasource, as we know that if you don't close the connection, will cause big error. But who could tell me that if I forget close the datasource, what will happen? do harm to my application for the database server? thanks


scjp,scjd,scea
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

It won't harm the database server, but it will likely cause a resource leak. Calling close() returns the connection to the pool. If you skip the call, the pool doesn't know it can give that connection to others until the connection times out.


[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
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
You only need one DataSource, so it is reasonable to obtain it once and cache it in a static variable. The DataSource is thread-safe, so it can be used simultaneously by any of the requesting threads.

It is very unlikely that there will be any problems arising from keeping one DataSource open.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

Ignore my response. I misread the question and answered about closing connections.

I agree with Roger that it is not necessary to close the data source. On an application server, the server often manages the data source anyway, so it stays open.
daming wang
Greenhorn

Joined: Jul 28, 2004
Posts: 27
That's ok, thank you all, Roger, Jeanne.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about datasource close?