File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Weak reference concept in Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Weak reference concept in Connection " Watch "Weak reference concept in Connection " New topic
Author

Weak reference concept in Connection

siva saran
Greenhorn

Joined: Mar 11, 2007
Posts: 17
Hi all,

I have the folowing code snippet


My doubt is
1) I do a getConnection two times but should I close two times using returnConnection or one returnConnection is enough.
2) I read about a concept called "Weak reference".Does this example point to that.Any more simplified explanation availabe
for the concept somewhere.
3) As of now , I have used two return connection (i have uncommented the code in the finally to avoid problems)but I feel its redundant.Please correct me if am wrong.
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
next time post a clean and idented code

Googling you'll find nice texts about weak references. But I don't think you need to use it.
Search for connection pool to enhance the performance.

yes, it's redundant. other thing I noticed, you are throwing and catching the exception in the same
method.

I changed the code a little:

siva saran
Greenhorn

Joined: Mar 11, 2007
Posts: 17
Thanks Leandro. I will keep your instruction in mind.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Weak reference concept in Connection
 
Similar Threads
Problem in getting the data from DB using servlets
JDBC Connection Pooling in Websphere
mysql connectivity with jboss
ClassNotFoundException while trying to connect to Oracle
Why cant connect to another computer in lan?