java.net.NoRouteToHostException: No route to host: connect

问题:
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
java.net.NoRouteToHostException: No route to host: connect

问题详情:

HTTP Status 500 – Internal Server Error
Type Exception Report

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: 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.
### The error may exist in CompanyDetail.xml
### The error may involve CompanyDetail.getTotalCompanyDetail
### The error occurred while executing a query
### Cause: 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.
    org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
    org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
    org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:136)
    top.hsocode.dao.CompanyDetailDao.getTotalCompanyDetail(CompanyDetailDao.java:23)
    top.hsocode.service.CompanyDetailService.getTotalCompanyDetail(CompanyDetailService.java:11)
    top.hsocode.servlet.CompanyDetailServlet.doGet(CompanyDetailServlet.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

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.
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:981)
    com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:339)
    com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
    com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286)
    com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)
    com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
    com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
    com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
    java.sql.DriverManager.getConnection(DriverManager.java:664)
    java.sql.DriverManager.getConnection(DriverManager.java:208)
    org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:201)
    org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196)
    org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93)
    org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138)
    org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60)
    org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
    org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84)
    org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
    org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
    org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
    org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
    org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
    org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
    org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
    org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:136)
    top.hsocode.dao.CompanyDetailDao.getTotalCompanyDetail(CompanyDetailDao.java:23)
    top.hsocode.service.CompanyDetailService.getTotalCompanyDetail(CompanyDetailService.java:11)
    top.hsocode.servlet.CompanyDetailServlet.doGet(CompanyDetailServlet.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

java.net.NoRouteToHostException: No route to host: connect
    java.net.DualStackPlainSocketImpl.connect0(Native Method)
    java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    java.net.Socket.connect(Socket.java:589)
    com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
    com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:298)
    com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
    com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286)
    com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)
    com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
    com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
    com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
    java.sql.DriverManager.getConnection(DriverManager.java:664)
    java.sql.DriverManager.getConnection(DriverManager.java:208)
    org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:201)
    org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196)
    org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93)
    org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138)
    org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60)
    org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
    org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84)
    org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
    org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
    org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
    org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
    org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
    org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
    org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
    org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:136)
    top.hsocode.dao.CompanyDetailDao.getTotalCompanyDetail(CompanyDetailDao.java:23)
    top.hsocode.service.CompanyDetailService.getTotalCompanyDetail(CompanyDetailService.java:11)
    top.hsocode.servlet.CompanyDetailServlet.doGet(CompanyDetailServlet.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat/9.0.10

原因是没有联网

已标记关键词 清除标记
我这机器有点怪.也不知道是什么原因.用jdbc去连mysql服务器的时候反正在以下三种情形会有三种结果: a:如果我这台机器不让他接上路由器或局域网,提示: 01:04:00,453 WARN SettingsFactory:109 - Could not obtain connection metadata com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: java.net.NoRouteToHostException: No route to host: connect b:如果我这台机器接上局域网,提示:(之前我用的另一家公司提供的宽带服务,机器接上网络后jdbc能正常连接服务器.) 23:59:28,921 WARN SettingsFactory:109 - Could not obtain connection metadata com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: java.net.ConnectException: Connection timed out: connect c:如果我这台机器接上我自己弄的一个猫(电开着),则能够正常连上服务器(我这个猫没有接宽带) 我现在想要的结果是在各种情况下我本机的应用都可通过jdbc提供的驱动去访问mysql服务器.还期望各位提供一个好的解决方案. 还有就是我把防火墙也关了.对a,b两种情况不起作用. [b]问题补充:[/b] 纳闷了.我现在接上局域网后通过jdbc就是不能连接mysql服务器,但我试了下如果我把网线接在我这没连网的猫上,通过jdbc就是能连上mysql服务器 [b]问题补充:[/b] 会不会是网络配置方面的问题呢.如果是该怎么解决.纳闷的很
虚拟机环境:nginx+fastDFS+fastDFS-nginx-module 可以在虚拟机中上传文件,在浏览器上也可以查看上传的文件。 @Test public void testUpload() throws Exception { ClientGlobal.init("/home/yazhou/Document/java/taotao/clint.conf"); TrackerClient trackerClient =new TrackerClient(); TrackerServer trackerServer =trackerClient.getConnection(); StorageServer storageServer =null; StorageClient storageClient =new StorageClient(trackerServer,storageServer); String[] strings= storageClient.upload_file("/home/yazhou/Pictures/BG/1352113505895.jpg","jpg",null); for (String string:strings){ System.out.println(string); } } java.net.NoRouteToHostException: 没有到主机的路由 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 org.csource.fastdfs.ClientGlobal.getSocket(ClientGlobal.java:107) at org.csource.fastdfs.StorageServer.<init>(StorageServer.java:45) at org.csource.fastdfs.TrackerClient.getStoreStorage(TrackerClient.java:158) at org.csource.fastdfs.StorageClient.newWritableStorageConnection(StorageClient.java:1938) at org.csource.fastdfs.StorageClient.do_upload_file(StorageClient.java:703) at org.csource.fastdfs.StorageClient.upload_file(StorageClient.java:164) at org.csource.fastdfs.StorageClient.upload_file(StorageClient.java:132) at org.csource.fastdfs.StorageClient.upload_file(StorageClient.java:114) at com.taotao.fastcast.FastTest.testUpload(FastTest.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页