This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes connection pooling doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connection pooling doubt" Watch "connection pooling doubt" New topic
Author

connection pooling doubt

rajareddya reddy
Ranch Hand

Joined: Jul 23, 2011
Posts: 49

I have am using weblogic for getting connection.


My doubt is I am printing
1)conn.isClosed()
2)conn
NOTE: here conn means weblogic connection






I observed the connection closed is TRUE. But still I am able to print the connection as mentioned in the output.

But as per my knowledge connection should be null after connection is closed. IS IT CORRECT?

Please advice
rajareddya reddy
Ranch Hand

Joined: Jul 23, 2011
Posts: 49
Dear All,

Please help.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

rajareddya reddy wrote:But as per my knowledge connection should be null after connection is closed. IS IT CORRECT?


If you mean that you think that closing a Connection object somehow assigns null to a variable which referred to that object, then no, that isn't correct. What is this knowledge of yours which told you such a thing?
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2337
    
  28

The Connection class is really a wrapper class that holds the native database connection. It's not the "real" connection. The connection is hidden from you. When a connection is closed, the object of the wrapping Connection class doesn't go away, just the underlying native connection is closed. Any references that you have to the Connection object will still be referencing a COnnection object.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

Jayesh A Lalwani wrote:When a connection is closed, the object of the wrapping Connection class doesn't go away, just the underlying native connection is closed. Any references that you have to the Connection object will still be referencing a COnnection object.

This principle is, however, true for all connections - physical as well as those from connection pools. Calling close() on a connection, or any other JDBC resource (such as ResultSet or PreparedStatement) closes the resource. Trying to use other methods of Connection, ResultSet or similar instance after close() has been called on it therefore usually causes an SQLException.

JDBC interfaces, including Connection, contain the isClosed() method, which could be used to see whether the resource was closed or not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connection pooling doubt