引起:java.net.NoRouteToHostException:没有到主机的路由 [英] Caused by: java.net.NoRouteToHostException: No route to host

查看:13255
本文介绍了引起:java.net.NoRouteToHostException:没有到主机的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在openshift上从eclipse部署我的Jersey项目,我在尾部文件中收到此错误引起:java.net.NoRouteToHostException:没有到主机的路由

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

之前我喜欢这样:

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

我收到此错误:


'java.lang.NumberFormatException:对于输入字符串:OPENSHIFT_MYSQL_DB_PORT'

'java.lang.NumberFormatException: For input string: "OPENSHIFT_MYSQL_DB_PORT"'




  • 我已经ping了这个IP地址 127.10.230.440 我收到了回复

  • 我检查了一些端口8080,3306是否正在使用我当地的mashine,但它们只是在eclipse中使用。

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

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


      推荐答案

      您的MySQL 正在侦听TCP / IP,因此您尝试连接失败。当你说:

      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:


      我检查了一些端口8080,3306是否正在使用我当地的mashine,但你有点回答了你的问题它们只是在eclipse中使用。

      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 在localhost上监听。要以另一种方式确认,请尝试从命令提示符连接到MySQL:

      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
      

      我希望这会失败。您的问题的解决方案是配置MySQL以侦听localhost。在 /etc/my.cnf 配置文件的[mysqld]行下,添加以下内容:

      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
      

      这不是Java问题,这是一个MySQL问题。

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

      这篇关于引起:java.net.NoRouteToHostException:没有到主机的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆