错误org.hibernate.util.JDBCExceptionReporter - 通信链接失败

时间:2013-11-25 13:27:08

标签: java mysql spring hibernate

我正在开发一个SpringMySQLHibernate项目,该项目还包含一个主应用程序,该应用程序在数据库中不断查看但是在几分钟的应用程序抛出异常之后

0    [Thread-1] ERROR org.hibernate.util.JDBCExceptionReporter  - Communications link failure

Last packet sent to the server was 1 ms ago.
Exception in thread "Thread-1" 3    [Thread-1] ERROR org.hibernate.util.JDBCExceptionReporter  - Communications link failure

Last packet sent to the server was 1 ms ago.
org.hibernate.exception.JDBCConnectionException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
    at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1596)
    at org.hibernate.loader.Loader.doQuery(Loader.java:717)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
    at org.hibernate.loader.Loader.doList(Loader.java:2294)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
    at org.hibernate.loader.Loader.list(Loader.java:2167)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1706)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
    at com.qait.cdl.commons.dao.impl.CDLHibernateDaoImpl.findAll(CDLHibernateDaoImpl.java:77)
    at com.qait.cdl.insertIsbn.InsertIsbnDatabaseLookup.run(InsertIsbnDatabaseLookup.java:27)
    at java.lang.Thread.run(Thread.java:724)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 1 ms 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:406)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2103)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
    at sun.reflect.GeneratedConstructorAccessor11.newInstance(Unknown Source)
    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:406)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:187)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:153)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:83)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
    ... 14 more
Caused by: java.net.NoRouteToHostException: Cannot assign requested address
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at java.net.Socket.<init>(Socket.java:425)
    at java.net.Socket.<init>(Socket.java:241)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2026)
    ... 30 more

我在许多链接上搜索但没有得到确切/满意的理由以及如何克服

2 个答案:

答案 0 :(得分:2)

根本原因是NoRouteToHostException,这意味着底层操作系统正在向JVM发送“无路由到主机”TCP / IP错误。这表示数据库服务器和本机之间存在网络问题;检查系统的操作系统日志(例如Linux上的dmesg)以查看网卡是否存在连接问题。如果没有,网络路由中存在间歇性问题,您需要与网络管理员进行故障排除。

答案 1 :(得分:1)

正如我所说,有一个主应用程序在数据库中不断寻找,每次命中数据库时使用套接字,当使用所有套接字时,它会提供NoRouteToHostException,由操作系统发送给JVM。为了重用套接字,我使用下面提到的命令 echo "1" >/proc/sys/net/ipv4/tcp_tw_reuse和/或echo "1" >/proc/sys/net/ipv4/tcp_tw_recycle,解释为here