JDBC-Mysql Amazon EC2连接 [英] JDBC-Mysql Amazon EC2 Connection
问题描述
我是服务器和数据库的新手.我一直在尝试测试一个Java应用程序,该应用程序可以连接,读取和修改Amazon ec2上托管的Mysql数据库.
I'm new to servers and databases. I've been trying to test out a java application that connects, reads and modifies a Mysql database that is hosted on amazon ec2.
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绑定到mysql config,我仍然无法建立连接(在进行其他搜索之后类似的问题)
The issue is that despite being able to connect using the credentials via Mysql workbench, adding 3306 to my security group, binding 0.0.0.0 to mysql config, I still can't get a connection going (after doing some searching of other similar problems on SO)
任何人都对什么地方可能出了错有什么见解?我尝试了getConnection()参数的许多变体.
Anyone have any insight as to what could be wrong? I have tried many variations of the getConnection() arguments.
推荐答案
connection = DriverManager.getConnection("jdbc:mysql://username@ec2-host/myDBname, MYSQLUSER, MYSQLPASS)
connection = DriverManager.getConnection("jdbc:mysql://username@ec2-host/myDBname, MYSQLUSER, MYSQLPASS)
这篇关于JDBC-Mysql Amazon EC2连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!