Bonjour,
Voilà, j'ai un problème quand je veut me connecter à ma base de données qui est située sur un serveur distant à partir d'un client java que j'ai développé. J'utilise un PuTTY pour faire le tunnel SSH avec les ports 3306 (MySQL).
Mes identifiants sont valides et j'ai bien compilé en précisant le driver dans le classpath.
Voici mon code :
import java.sql.*;
class connexion
{
StringBuffer resultat= new StringBuffer();
int nCol;
public connexion ()
{
envoiRequete ();
}
void envoiRequete()
{
//Connexion
try
{
String nomDriver = "com.mysql.jdbc.Driver";
Connection conn=null;
try
{
Class.forName(nomDriver);
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/freez","hote","");
}
catch(ClassNotFoundException cnfe)
{
System.out.println("La classe "+nomDriver+" n'a pas été trouvée");
cnfe.printStackTrace();
}
//Requete
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from event;");
ResultSetMetaData rsmd = rs.getMetaData ();
while (rs.next ())
{
String tmp= "";
for (int i = 1; i <= nCol ; ++i)
{
switch (rsmd.getColumnType (i))
{
case Types.INTEGER:
tmp = ""+rs.getInt (i);
break;
case Types.CHAR:
tmp = ""+rs.getString (i);
break;
default:
System.out.println("Type non implémenté");
break;
}
resultat.append (tmp+"\t");
}
resultat.append ("\n");
}
//Affichage du resultat
System.out.println(resultat.toString());
//Fin de connexion
conn.close();
}
catch (SQLException ex)
{
System.out.println("Exception: " + ex.toString());
ex.printStackTrace() ;
}
}
public static void main(String argv[])
{
new connexion ();
}
}
Quand je lance le programme, l'accès à la base de donnée m'est refusée :
URL jdbc:mysql://localhost:3306/freez
Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communicatio
ns link failure
Last packet sent to the server was 0 ms ago.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link fai
lure
Plus tout un tas d'erreurs qui sont causées par ce refus de connexion.
S'il vous plait, aidez moi, cela fait 3 jour que je me casse la tête sur ce problème.
Configuration: Windows Vista
Firefox 2.0.0.12