我正在尝试连接到 mysql 数据库,但我不断收到错误消息: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
我知道网址应该是:“jdbc:mysql://server-url:3306”
这是代码:
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;
}
}
有任何想法吗?
另外,Godaddy 询问我是否想要DSN。那是什么意思?我需要吗?
谢谢