如何使用 jdbc 连接到 jelastic 数据库
private static final String USER = "user";
private static final String PASS = "pass";
private static final String URL = "jdbc:mysql://node30220-learning.j.dnr.kz/user";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(URL, USER, PASS);
stmt = conn.createStatement();
String sql;
sql = "SELECT * FROM DUAL";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Goodbye!");
}
一切似乎都是正确的,但我得到一个例外
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
你好,
问题很可能是您没有连接到 MySQL 容器的外部 IP 地址。请连接外部 IP 并重试。为方便起见,您可以使用我们的远程访问 MySQL/MariaDB手册。