简体   繁体   English

java.net.ConnectException:连接被拒绝:connect openshift

[英]java.net.ConnectException: Connection refused: connect openshift

I have an application on Openshift I'm trying to connect to MySQL DB my code is : 我在Openshift上有一个应用程序,我正在尝试connectMySQL DB我的代码是:

private static final String URL = "jdbc:mysql://127.11.240.130:3306/"
        + DB_NAME;
public static String initConnection() {
    if (connection == null) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(URL, USER_NAME,
                    PASSWORD);
            return "Connection Initialized!";
        } catch (SQLException e) {
            e.printStackTrace();
            return e.getMessage();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            return e.getMessage();
        }
    }
    return "Connection Initialized!";
}

and in index.jsp code is : index.jsp代码是:

<p><% out.print(""+com.measyou.DbManager.initConnection()); %> </p>

this code gives me 这段代码给了我

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

and Caused by : Caused by以下原因Caused by

Caused by: java.net.ConnectException: Connection refused: connect

I have referred This Link and This one as well, but Im unable to solve this problem. 我刚才提到这个链接这一次为好,但是我无法来解决这个问题。 Please Help me in solving this one. 请帮助我解决这一问题。

Is this a scaled application, or is it running in a single gear? 这是可扩展的应用程序,还是单步运行? Either way, you should be using OPENSHIFT_MYSQL_DB_HOST and OPENSHIFT_MYSQL_DB_PORT instead of hard-coding the IP and port. 无论哪种方式,您都应该使用OPENSHIFT_MYSQL_DB_HOST和OPENSHIFT_MYSQL_DB_PORT,而不是硬编码IP和端口。 And are you sure the mysqld is running? 并且您确定mysqld正在运行? Run the following: 运行以下命令:

ps -ef | grep mysqld

and you should see running processes. 并且您应该看到正在运行的进程。 Then run: 然后运行:

netstat -plnt | grep $OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT

if it's running properly, you should see a line like this: 如果运行正常,您应该会看到如下一行:

tcp 0 0 127.11.240.130:3306 0.0.0.0:* LISTEN 459740/mysqld

if the process is not running, or it's not listening on the port as expected, then check the mysql logs in ~/mysql/log/ for errors. 如果该进程未在运行,或者没有按预期在端口上侦听,请检查〜/ mysql / log /中的mysql登录是否有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java Mail错误:java.net.ConnectException:连接被拒绝:connect - Java Mail Error : java.net.ConnectException: Connection refused: connect Java套接字 - java.net.ConnectException:连接被拒绝:连接 - Java sockets - java.net.ConnectException: Connection refused: connect Java网络问题:java.net.ConnectException:连接被拒绝:连接 - Java Networking Problem: java.net.ConnectException: Connection refused: connect Java 中的 ssh 异常:java.net.ConnectException:连接被拒绝:连接 - ssh Exception in Java: java.net.ConnectException: Connection refused: connect java.net.ConnectException:连接被拒绝:connect java nio - java.net.ConnectException: Connection refused: connect java nio java.net.ConnectException:拒绝连接:连接HTTPS连接 - java.net.ConnectException: Connection refused: connect for HTTPS connections 获取java.net.ConnectException:连接被拒绝:在Eclipse中连接 - Getting java.net.ConnectException: Connection refused: connect in eclipse RMI(java.net.ConnectException:连接被拒绝:连接) - RMI(java.net.ConnectException: Connection refused: connect) java.net.ConnectException:连接被拒绝:用 Spring boot 连接 Solr - java.net.ConnectException: Connection refused: connect Solr with Spring boot java.net.ConnectException:连接被拒绝:检索文件时连接 - java.net.ConnectException: Connection refused: connect when retrieving a file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM