【问题标题】:Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException引起:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
【发布时间】:2013-08-03 09:05:27
【问题描述】:

在我的产品服务器上遇到异常,但它会在几个小时后自动解决。这个问题可能是什么原因

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was234747 milliseconds ago.The last packet sent successfully to the server was 234747 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.

我们已经设置了 autoReconnect=true,从论坛我发现我们需要启用空闲连接测试。请指教

会不会是应用程序中任何未关闭的连接导致这个异常?

我们使用的是Ibatis,下面是Ibatisconfig文件

<transactionManager type="JDBC" commitRequired="true">
    <dataSource type="SIMPLE">
        <property name="JDBC.Driver" value="com.mysql.jdbc.Driver" />
        <property name="JDBC.ConnectionURL"
            value="<URL>?autoReconnect=true" />
        <property name="JDBC.Username" value="<username>" />
        <property name="JDBC.Password" value="<password>" />
        <property name="JDBC.DefaultAutoCommit" value="false" />
        <property name="Pool.TimeToWait" value="100" />
        <property name="Pool.PingQuery" value="select 1" />
        <property name="Pool.PingEnabled" value="true" />
        <property name="Pool.PingConnectionsOlderThan" value="300000" />
        <property name="Pool.PingConnectionsNotUsedFor" value="300000" />
    </dataSource>
</transactionManager>

【问题讨论】:

标签: java mysql jdbc ibatis


【解决方案1】:

嗯,在我的项目中,我遇到了同样的问题。我们使用 mysql,如果连接空闲 8 小时,则 db 将不可用。我们使用的解决方案是使用 C3P0 连接池。在这里检查一下。 http://www.mchange.com/projects/c3p0/

【讨论】:

  • 他们有 Ibatis 的选项吗,我听说是 Hibernate 的选项
  • 我们以前从未使用过 Ibatis。在阅读了您的评论后,我用谷歌搜索了它,并找到了一篇文章。希望这会对你有所帮助。opendebug.com/article/447235
猜你喜欢
  • 2013-12-02
  • 1970-01-01
  • 2016-04-29
  • 2012-09-17
  • 2014-12-31
  • 2011-02-28
相关资源
最近更新 更多