title: MySql connection over connection pool can not be restored
body: <p>I have a BasicDataSource instance and a jdbctemplate uses that. </p>
  
  <p>So after some idle time it always says:</p>
  
  <pre><code>Caused by: java.sql.SQLException: Could not retrieve transation read-only status server
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:949)
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
          at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3976)
          at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3947)
          at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2295)
          at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2262)
          at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2246)
          at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
          at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
          at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:916)
          at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:909)
          at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:644)
          ... 39 more
  Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
  
  The last packet successfully received from the server was 30,457,725 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
          at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
          at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1127)
          at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3715)
          at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3604)
          at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4155)
          at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
          at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
          at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2832)
          at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2781)
          at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1569)
          at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3970)
          ... 48 more
  Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
          at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3161)
          at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3615)
          ... 56 more
  </code></pre>
  
  <p>And the bean definition for datasource is:</p>
  
  <pre><code>&lt;bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="url" value="jdbc:mysql://1.2.3.4:3306/?autoReconnectForPools=true"/&gt;
      &lt;property name="username" value="root"/&gt;
      &lt;property name="password" value="password"/&gt;
      &lt;property name="initialSize" value="${datasourceInitialPoolSize}"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Any ideas?</p>