13/01/2008

DBCP: SQL Error: 17410

Database connection pool
Sometimes when you put your application in Production, you can get an sql exception, database connection error
ERROR - JDBCExceptionReporter - No more data to read from socket (java.sql.SQLException: No more data to read from socket)
JDBCExceptionReporter - SQL Error: 17410, SQLState: null
JDBCExceptionReporter - SQL Error: 0, SQLState: null (at org.hibernate.jdbc.ConnectionManager.aggressiveRelease(ConnectionManager.java:400))

The origin of the problem is due to how you manage your datasource and the connection manager.
Usually, the issue not detected in Development, because the default configuration of you pool manager is right, but in Production, the default configuration can be weak.
If you meet theses kind of exception, it is because the pool does not clean "dead" connection. It can be easily customized in the configuration of the pool.

For example: with dbcp (apache.commons.dbcp)



<bean id="MyDatasource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="..." />
<property name="url" value="..." />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="defaultAutoCommit" value="true" />
<property name="maxActive" value="10" />
<property name="maxWait" value="120000" />
<property name="validationQuery" value="select 1 from dual" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="10000" />
<property name="numTestsPerEvictionRun" value="3" />
<property name="minEvictableIdleTimeMillis" value="1800000" />
<!--property name="poolPreparedStatements" value="true" /--><!--leave it to false with Spring and Hibernate-->
<!--property name="maxOpenPreparedStatements" value="40" /-->
</bean>