I'm trying to connect my application to a remote server database with JDBC connector, but I get a connection error each time.
ConnexionBDD.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnexionBDD {
private static final String dbURL = "jdbc:mysql://**my_server_ip_address**/**my_db_name**:3306?useUnicode=yes&characterEncoding=UTF-8&connectTimeout=3000";
private static final String user = "**my_username**";
private static final String password = "**my_password**";
private static Connection connexion = null;
/**
* Connexion a la base de donnees; chargement du driver
*
* @throws ClassNotFoundException
* @throws SQLException
*/
private ConnexionBDD() throws ClassNotFoundException, SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
try {
connexion = DriverManager.getConnection(dbURL, user, password);
System.out.println("Connexion BDD Ok");
} catch (SQLException e) {
System.out.println("Erreur Connexion BDD : " + e.getMessage());
}
} catch (ClassNotFoundException e) {
System.out.println("Erreur Chargement Driver" + e.getMessage());
}
}
/**
* Recuperation de la connexion
*
* @return la connexion
* @throws ClassNotFoundException
* @throws SQLException
*/
public static Connection getConnexion() throws ClassNotFoundException, SQLException {
if (connexion == null) {
new ConnexionBDD();
}
return connexion;
}
}
When I try to call the getConnexion()
method :
Connection connexion = ConnexionBDD.getConnexion() ;
I'm getting this error as output :
Erreur Connexion BDD : 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.
Note that when I try to connect on a local server it works perfectly, but not on a remote server..