linux tomcat MySql连接失败

时间:2016-03-16 10:14:56

标签: mysql linux tomcat

我有一台运行在Linux上的tomcat服务器访问远程MySql服务器,突然间,没有任何配置/程序的变化或我所知道的任何事情,我开始得到以下错误跟踪:

SQLException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. [Ljava.lang.StackTraceElement;@12fd02da
 And the error stack is: 
 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. 
 The driver has not received any packets from the server. 
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
 at java.lang.reflect.Constructor.newInstance(Constructor.java:422) 
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) 
 at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:983) 
 at com.mysql.jdbc.MysqlIO.(MysqlIO.java:339) 
 at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2252) 
 at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2285) 
 at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2084) 
 at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:795) 
 at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:44) 
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
 at java.lang.reflect.Constructor.newInstance(Constructor.java:422) 
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) 
 at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400) 
 at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327) 
 at java.sql.DriverManager.getConnection(DriverManager.java:664) 
 at java.sql.DriverManager.getConnection(DriverManager.java:247) 
 at com.localhost.AtW.servlets.Dispatcher.doGet(Dispatcher.java:66) 
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) 
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 
 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 
 at org.apache.catalina.filters.CorsFilter.handleNonCORS(CorsFilter.java:436) 
 at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:177) 
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) 
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) 
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) 
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) 
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) 
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) 
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) 
 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) 
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
 at java.lang.Thread.run(Thread.java:745) Caused by: java.net.NoRouteToHostException: No route to host 
 at java.net.PlainSocketImpl.socketConnect(Native Method) 
 at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) 
 at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) 
 at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) 
 at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) 
 at java.net.Socket.connect(Socket.java:589) 
 at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:214) 
 at com.mysql.jdbc.MysqlIO.(MysqlIO.java:298) ... 41 more 

此外,我通常在启动计算机后发出Linux命令service iptables start,这会导致向根发送邮件,说明存在错误。到目前为止,一切都运转良好。

今天,邮件也被发送但是,这也很奇怪,邮件显示明天的日期,即使输入命令date我看到了正确的日期和时间。我不知道这两件事之间是否有任何联系。

我不知道问题是什么以及从哪里开始寻找。

任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

我偶然发现了这个问题!!!

虽然Linux机器具有静态IP,但运行MySQL的机器配置为使用DHCP。似乎网络交换机重新启动,并且偶然地,该机器收到了不同的IP,因此TOMCAT无法通信(错误的IP)。

我知道......在发布问题之前我应该​​检查一下。

无论如何,这可能对某些人有用......