jdbc4 CommunicationsException [英] jdbc4 CommunicationsException

查看:235
本文介绍了jdbc4 CommunicationsException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台机器运行一个java应用程序,与在同一个实例上运行的mysql实例交谈。应用程序
使用来自mysql的jdbc4驱动程序。我不断收到com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
随机时间。



这里是整个消息。



无法为事务打开JDBC连接;嵌套异常

  com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:从服务器成功接收的最后一个数据包是25899毫秒前。成功发送到服务器的最后一个数据包是25899毫秒,这比服务器配置的值wait_timeout长。您应该考虑在应用程序中使用之前过期和/或测试连接有效性,增加客户端超时的服务器配置值,或使用Connector / J连接属性autoReconnect = true来避免此问题。 

对于mysql,global'wait_timeout'和'interactive_timeout'的值设置为3600秒, connect_timeout'设置为60秒。等待超时值远高于26秒(25899毫秒)。



我使用dbcp作为连接池,这里是数据源的spring bean配置。

 < bean id =dataSourcedestroy-method =closeclass =org.apache.commons.dbcp.BasicDataSource> 
< property name =driverClassNamevalue =com.mysql.jdbc.Driver/>
< property name =urlvalue =jdbc:mysql:// localhost:3306 / db/>
< property name =usernamevalue =xxx/>
< property name =passwordvalue =xxx/>
< property name =poolPreparedStatementsvalue =false/>
< property name =maxActivevalue =3/>
< property name =maxIdlevalue =3/>
< / bean>

任何想法为什么会发生这种情况?将使用c3p0解决问题?

解决方案

尝试正确设置Apache Commons DBCP。



您需要设置:




  • validationQuery to SELECT 1 + 1

  • testOnBorrow to true



这应该可以解决问题。


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.

Here is the whole message.

Could not open JDBC Connection for transaction; nested exception is

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.

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.

I use dbcp for connection pooling and here is spring bean config for the datasource.

   <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource" >
          <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
                    <property name="url" value="jdbc:mysql://localhost:3306/db"/>
                <property name="username" value="xxx"/>
                <property name="password" value="xxx" />
                    <property name="poolPreparedStatements" value="false" />
            <property name="maxActive" value="3" />
            <property name="maxIdle" value="3" />
    </bean>

Any idea why this could be happening? Will using c3p0 solve the problem ?

解决方案

Try setting up the Apache Commons DBCP correctly.

You need to set:

  • validationQuery to SELECT 1+1
  • testOnBorrow to true

That should fix the problem.

这篇关于jdbc4 CommunicationsException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆