title: jdbc4 CommunicationsException
body: <p>I have a machine running a java app talking to a mysql instance running on the same instance. the app
   uses jdbc4 drivers from mysql. I keep getting com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
   at random times. </p>
  
  <p>Here is the whole message. </p>
  
  <p>Could not open JDBC Connection for transaction; nested exception is </p>
  
  <pre><code>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was25899 milliseconds ago.The last packet sent successfully to the server was 25899 milliseconds ago, which  is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
  </code></pre>
  
  <p>For mysql, the value of global 'wait_timeout' and 'interactive_timeout' is set to 3600 seconds and 'connect_timeout' is set to 60 secs. the wait timeout value is much higher than the 26 secs(25899 msecs).  mentioned in the exception trace.</p>
  
  <p>I use dbcp for connection pooling and here is spring bean config for the datasource.</p>
  
  <pre><code>   &lt;bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource" &gt;
            &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
                      &lt;property name="url" value="jdbc:mysql://localhost:3306/db"/&gt;
                  &lt;property name="username" value="xxx"/&gt;
                  &lt;property name="password" value="xxx" /&gt;
                      &lt;property name="poolPreparedStatements" value="false" /&gt;
              &lt;property name="maxActive" value="3" /&gt;
              &lt;property name="maxIdle" value="3" /&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>Any idea why this could be happening?  Will using c3p0 solve the problem ?</p>