- My local machine is running Ubuntu 11.10. I use Eclipse Indigo as my IDE.
- My server is a BitNami LampStack (Ubuntu 10) running on Amazon EC2.
- I am relatively experienced in both .Net and Java, but a beginner in JDBC, MySQL Administration, Linux, and EC2.
I have successfully opened port 3306, and MySQL Workbench can connect correctly. User ‘root’@’%’ has full privileges to everything, and no default database.
After struggling with a no-suitable-driver-found issue, I finally just put the mysql-connector-java-5.0.8-bin.jar directly in my Java Project. I realize this is probably sub-optimal, but it seems to work. I did it (after much Googling) because I can’t figure out how to install it correctly on Ubuntu, and am worried it will be harder through ssh to EC2, so I figured it could just compile into the project. A link would be appreciated, as it would be nice to fix that also.
The following is the code that throws the Exception. This is at the top of main; nothing executes first.
I have tried this with and without the Class.forName(…) and also using a java.util.Properties for the credentials. Identical credentials work from MySQL Workbench on same machine, which I have copy+pasted several times to ensure no typos.
I altered the passwords and addresses for the sake of security, though keeping the format. To be explicit, the password here is “Abcdef1234#”. For all I know, the # may be the culprit.
Class.forName("com.mysql.jdbc.Driver");
String CONNECTION_STRING = "jdbc:mysql://ec2-87-212-16-34.compute-1.amazonaws.com?user=root&password=Abcdef1234#";
Connection cn = DriverManager.getConnection(CONNECTION_STRING);
Which then throws:
Exception in thread "main" java.sql.SQLException: Access denied for user 'root'@'ppp-72-135-32-239.dsl.hgyuct.swbell.net' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1247)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:222)
at Program.main(Program.java:5)
Let me know if I should include any more information.
The problem was that the
'root'@'localhost'password was different than the'root'@'%'password, so connecting from JDBC used what I thought was the old password.