Issues connecting to remote AWS Database through intellij.

Answered

I am having issues connecting to a remote MySQL DB that I set up through AWS. When creating the DB, I ensured that it is publicly accessible, and that I have the Username, Password, Database name, and Database instance typed out correctly. In my code on intellij, I connect with the following:

public String host = "jdbc:mysql://database-instance-name.12-random-chars.us-east 2.rds.amazonaws.com:3306/database-name";
public String userName = "-----DB";
public String passWord = "--------------";
public Connection con;
public Statement statement;
public void connect() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection(host, userName, passWord);
statement = con.createStatement();
JOptionPane.showMessageDialog(null, "Successfully connected to the database!", 
"Success",
JOptionPane.ERROR_MESSAGE);
} catch (SQLException | ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, e.toString(), "Error",
JOptionPane.ERROR_MESSAGE);
}
}

but I am not able to connect to my remote MySQL DB. Instead, I receive the following error:

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

So it sounds like I am connecting, and sending successfully, but not receiving any data. So I use telnet, and try to connect on the port 3306 (which is what my AWS panel specified) and I receive this following error:

"C:\-----\----->telnet database-instance-name.12-random-chars.us-east-2.rds.amazonaws.com 3306
Connecting To database-instance-name.12-random-chars.us-east-2.rds.amazonaws.com...Could not open connection to the host, on port 3306: Connect failed"

I am confused as I believe the inbound and outbound rules are set properly, and that I it is publicly accessible. 
And the rules for the security group is set to accept all.
This is the error that I receive when I try to connect to it:




The reason why I am looking to the intellij support forums is because I have already posted on the AWS forums on Amazon's website, but have yet to receive a response, so I am helping that someone has worked with Amazon's MySQL DB's and can help me here, thank you in advance!

1
3 comments

Double check the remote database configuration: make sure the instance is up and running and is configured for TCP incoming connection on the specified port. Double check bind-addressport in my.cnf config.

Check also https://stackoverflow.com/a/10772407/2000323.

0
Avatar
Permanently deleted user

Hi!!

I am facing the same issue while making the connection between AWS Aurora and JAVA as above.

Did you find a solution to it?

If yes, can you please reply back at email : manpreetkaurassi@gmail.com

It will be very helpful.

Thanx!

0

Please sign in to leave a comment.