MrPencil
MrPencil

Reputation: 964

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

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

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

Upvotes: 3

Views: 21833

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522331

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.

Upvotes: 2

Related Questions