Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connection pooling doubt

 
rajareddya reddy
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

Please help.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic