1

I'm doing a Java project where it needs to connect it to a database. but there's the problem is when I run my code it shows me the exception:

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

Here is my code:

public Connection cc;
public Statement stm;
public ResultSet rr;

public void Class() {

    try {
        Class.forName("com.mysql.jdbc.Driver");
        cc = DriverManager.getConnection("jdbc:mysql://69.89.31.241:2083/table", "user", "pass");
        JOptionPane.showMessageDialog(null, "Connection Ok");
    } catch (Exception e) {
       System.out.println(e);
    }
}

Now if I try this way in localhost it works but not on my live server. My server is Server: Localhost via UNIX socket.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

First things first:

  • Check your network connection to the external IP where you've hosted your MySQL Database
  • Try to connect to the MySQL Database using a client like SQL Yog
  • Once these steps are done, you'll know if there are any issues in connecting to the MySQL database at all
  • Even after these if you are not able to connect to your MySQL database, then you will have to make the following change on your my.cnf file

my.cnf:

bind-address = 69.89.31.241

And if you don't have any user login issues, you should be able to connect to the MySQL Database from your Java code.

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46