【发布时间】:2014-05-17 22:05:47
【问题描述】:
我在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!";
}
index.jsp 中的代码是:
<p><% out.print(""+com.measyou.DbManager.initConnection()); %> </p>
这段代码给了我
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
和Caused by:
Caused by: java.net.ConnectException: Connection refused: connect
【问题讨论】: