我是服务器和数据库的新手。我一直在尝试测试连接、读取和修改托管在 amazon ec2 上的 Mysql 数据库的 java 应用程序。
System.out.println("-------- MySQL JDBC Connection Testing ------------");
String DNS = "MYDNS";
String myDBname = "DBNAMe"
String MYSQLUSER = "USER";
String MYSQLPW = "PW";
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your MySQL JDBC Driver?");
e.printStackTrace();
return;
}
System.out.println("MySQL JDBC Driver Registered!");
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:mysql://" +DNS+@"/"+myDBname, MYSQLUSER, MYSQLPASS)
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
currentDir = "broke";
}
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
问题是,尽管能够通过 Mysql 工作台使用凭据进行连接,将 3306 添加到我的安全组,将 0.0.0.0 绑定(bind)到 mysql 配置,但我仍然无法建立连接(在搜索其他SO上的类似问题)
任何人都知道什么可能是错的?我尝试了 getConnection() 参数的多种变体。
最佳答案
connection = DriverManager.getConnection("jdbc:mysql://username@ec2-host/myDBname, MYSQLUSER, MYSQLPASS)
关于java - JDBC-Mysql Amazon EC2连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13428077/