gpt4 book ai didi

java - 由 : java.net.NoRouteToHostException: No route to host 引起

转载 作者:行者123 更新时间:2023-11-30 08:52:14 46 4
gpt4 key购买 nike

我正尝试在 openshift 上从 eclipse 部署我的 Jersey 项目,但尾文件中出现此错误 Caused by: java.net.NoRouteToHostException: No route to host

之前我有这样的经历:

String host = "jdbc:mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/bustrackerserver"

我遇到了这个错误:

'java.lang.NumberFormatException: For input string: “OPENSHIFT_MYSQL_DB_PORT”'

  • 我已经对这个 IP 地址 127.10.230.440 执行了 ping 操作,我收到了回复
  • 我检查了一些端口 8080、3306 是否正在从我的本地机器中使用,但它们只是从 eclipse 中使用。

苹果类。

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!";
}
}

最佳答案

您的 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.

换句话说,MySQL 在本地主机上监听。要以另一种方式确认这一点,请尝试从命令提示符连接到 MySQL:

mysql -u adminNMccsBr -h 127.10.230.440 -p YOUR_DB_NAME

我预计这会失败。您的问题的解决方案是将 MySQL 配置为在本地主机上监听。在 /etc/my.cnf 配置文件中,在 [mysqld] 行下,添加以下内容:

bind-address = 127.10.230.440

这不是 Java 的问题,这是 MySQL 的问题。

关于java - 由 : java.net.NoRouteToHostException: No route to host 引起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30238067/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com