I’m trying to connect to a mysql db, but I keep getting error:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
I know the url suppose to be: “jdbc:mysql://server-url:3306”
here is the code:
import java.sql.Connection;
import java.sql.DriverManager;
public class FT_Database_Connection{
private Connection connection;
public FT_Database_Connection(String url, String username, String password){
try{
System.out.println("Loading driver...");
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver loaded!");
String user = username;
String db_pw = password;
System.out.println(url);
System.out.println(username);
System.out.println(password);
Connection test = DriverManager.getConnection(url, user, db_pw);
}catch(Exception e){
System.out.println("Couldn't get database connection.");
e.printStackTrace();
}
}
public Connection get_connection(){
return this.connection;
}
}
Any ideas?
Also, Godaddy ask if I want DSN. What’s that mean? Do I need it?
Thanks
If memory serves, GoDaddy has a couple of different MySQL DB implementations you can choose. One that allows for remote access, and one that does not. Are you sure that you have chosen the correct one?
Have you tried connecting remotely using MySQL Workbench first? Or even telnetting to the port? That will ensure you have the right db name and permissions to connect remotely. Once you can confirm that works, getting the code to work should be easier.