[英]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
上有一个应用程序,我正在尝试connect
到MySQL 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.