引起:java.net.NoRouteToHostException:没有到主机的路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30238067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Caused by: java.net.NoRouteToHostException: No route to host
提问by MrPencil
I am trying to deploy my Jersey project from eclipse on openshift and I am getting this error in the tail files Caused by: java.net.NoRouteToHostException: No route to host
我正在尝试在 openshift 上从 Eclipse 部署我的 Jersey 项目,但在尾部文件中出现此错误 Caused by: java.net.NoRouteToHostException: No route to host
before when I had like this:
之前我有这样的:
String host = "jdbc:mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/bustrackerserver"
I got this error:
我收到此错误:
'java.lang.NumberFormatException: For input string: “OPENSHIFT_MYSQL_DB_PORT”'
'java.lang.NumberFormatException:对于输入字符串:“OPENSHIFT_MYSQL_DB_PORT”'
- I have pinged this ip address
127.10.230.440
and I am getting response - I checked whether some of the port 8080, 3306 are being used from my local mashine but they are just being used from eclipse.
- 我已经 ping 这个 IP 地址
127.10.230.440
,我得到了回应 - 我检查了我的本地机器是否正在使用某些端口 8080、3306,但它们只是在 eclipse 中使用。
Apple class.
苹果课。
package org.busTracker.serverSide;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Map;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* Root resource (exposed at "myresource" path)
*/
@Path("myresource")
public class Apple {
//String host = " jdbc:mysql://${env.OPENSHIFT_MYSQL_DB_HOST}:${env.OPENSHIFT_MYSQL_DB_PORT}/serv??erside";
//String host = "jdbc:mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/bustrackerserver";
String host = "jdbc:mysql://127.10.230.440:3306/bustrackerserver";
String user = "adminNMccsBr";
String password = "K3SV5rbxh8qP";
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
* @return String that will be returned as a text/plain response.
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getIt() {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to database…");
conn = DriverManager.getConnection(host,user,password);
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
System.out.format("%s=%s%n",
envName,
env.get(envName));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// ignore
}
}
}
return "Hello, from apple class 14.05.15 13:30!";
}
}
回答by Tim Biegeleisen
Your MySQL is notlistening on TCP/IP and hence your attempt to connect is failing. You sort of answered your question when you said:
您的 MySQL未侦听 TCP/IP,因此您的连接尝试失败。当你说:
I checked whether some of the port 8080, 3306 are being used from my local mashine but they are just being used from eclipse.
我检查了我的本地机器是否正在使用某些端口 8080、3306,但它们只是在 eclipse 中使用。
In other words, MySQL is notlistening on localhost. To confirm this another way, try connecting to MySQL from the command prompt:
换句话说,MySQL不监听本地主机。要以另一种方式确认这一点,请尝试从命令提示符连接到 MySQL:
mysql -u adminNMccsBr -h 127.10.230.440 -p YOUR_DB_NAME
I expect this to fail. The solution to your problem is to configure MySQL to listen on localhost. In the /etc/my.cnf
config file, under the [mysqld] line, add the following:
我希望这会失败。您的问题的解决方案是将 MySQL 配置为在 localhost 上侦听。在/etc/my.cnf
配置文件的 [mysqld] 行下,添加以下内容:
bind-address = 127.10.230.440
This is not a Java problem, it's a MySQL problem.
这不是 Java 问题,而是 MySQL 问题。