commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <>
Subject Re: [dbcp] auto reconnecting
Date Wed, 07 Oct 2015 22:22:51 GMT
On 10/7/15 12:35 PM, Pruitt, Byron S wrote:
> My server has long standing idle periods.  We are seeing:  com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
The last packet successfully received from the server was...  errors.
> I would like to fix it as simply as possible.  MySQL has two properties autoReconnect
and autoReconnectForPools that might fix the problem.  They both default to false and I can't
find an easy way to set them.
> I had an earlier problem with auto commit and I fixed it with the setDefaultAutoCommit
method on PoolableConnectionFactory.  But, it doesn't have a similar setter for auto reconnect.
> The only example I found of setting the autoReconnect property is on the connection url.
 I use the interface where I pass an instance of Properties, so I assume I can set those properties
with it.
> I am curious if there are better ways to set those properties.

If you are using BasicDataSource, you can use it's
addConnectionProperty method to add driver-specific connection
properties such as this.  Just make sure to add the property before
you use the datasource.

You can achieve the same effect by enabling validation on borrow or
while idle (testOnBorrow, testWhileIdle).

> Thanks.
> -SP
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message