commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Lea <ja...@kumachan.net.nz>
Subject Re: DBCP: Closed connections
Date Wed, 23 Apr 2003 22:20:58 GMT
Behrens Matt - Grand Rapids wrote:
> Jason Lea wrote:
> 
>> Are you catching the SQLExecption in your try/catch/finally block?
>> If you suspect the connection is no good, you could use 
>> pool.invalidateObject(conn).  I guess you need to try and close the 
>> connection before you do this to tidy up any other statements/resultsets
>> that might be open.
> 
>  >
> 
>>  From the JavaDocs for invalidateObject():
>> "This method should be used when an object that has been borrowed is 
>> determined (due to an exception or other problem) to be invalid."
> 
> 
> Yeah, I am, but I see two problems with this approach.
> 
> 1.  It would seem I'd have to keep a reference to the pool accessible to 
> everything that can catch an SQLException, so they could invalidate the 
> object.  Unless I can somehow grab the pool from the connection (don't 
> see a way to do that), or maybe indirectly from the JDBC DriverManager?
> 
> 2.  I'd have to patch everything that can catch an SQLException, so they 
> could invalidate the object.
> 
> I guess if I want to keep DBCP virgin, though, this would be the way to go.

I don't think you can get the pool from the Connection.

I have a 'Global' singleton which holds my pool and pooling datasource. 
  I also have a couple of methods getConnection(), closeConnection() and 
I will probably add one called invalidateConnection().  When I opena a 
connection I put the hashCode and the time it was opened into a list. 
When closing I remove it.  I can check this list at anytime to see how 
long/how many connections are open.  I also log the opens and closes.

The invalidateConnection() will probably close the connection, remove it 
from my list, and then call pool.invalidateObject()

I can get a reference to Global from any piece of code, so I don't need 
to hold a reference to the pool when I am accessing the connection.

-- 
Jason Lea


Mime
View raw message