Caused by: java.net.NoRouteToHostException: No route to host

拈花ヽ惹草 提交于 2019-12-20 03:00:21

问题


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

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”'

  • 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.

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

回答1:


Your MySQL is not listening on TCP/IP and hence your attempt to connect is failing. You sort of answered your question when you said:

I checked whether some of the port 8080, 3306 are being used from my local mashine but they are just being used from eclipse.

In other words, MySQL is not listening on localhost. To confirm this another way, try connecting to MySQL from the command prompt:

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:

bind-address = 127.10.230.440

This is not a Java problem, it's a MySQL problem.



来源:https://stackoverflow.com/questions/30238067/caused-by-java-net-noroutetohostexception-no-route-to-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!