IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JDBC Java Discussion :

Problème de connexion BDD MySql


Sujet :

JDBC Java

  1. #1
    Membre habitué
    Homme Profil pro
    Développeur de jeux vidéo
    Inscrit en
    Mai 2014
    Messages
    227
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur de jeux vidéo
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2014
    Messages : 227
    Points : 162
    Points
    162
    Par défaut Problème de connexion BDD MySql
    Bonjour à tous, j'essaye de me connecter à ma db pour écrire une table (test). J'ai écrit ce code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
     
    package game;
     
    import java.sql.DriverManager;
    import java.sql.SQLException;
     
    import com.mysql.jdbc.Connection;
    import com.mysql.jdbc.Statement;
     
    public class Annagramme 
    {
    	public static void main( String[] args )
    	{
    		String url 		= "jdbc:mysql://db701563717.db.1and1.com"; // ou "jdbc:mysql://db701563717.db.1and1.com:3306/db701563717";
     
    		String login 	= "****************";
    		String pass 	= "****************";
    		String personne = "Max";
    		Connection cn 	= null;
    		Statement st 	= null;
     
    		try {
    			DriverManager.registerDriver(new com.mysql.jdbc.Driver ());
    			System.out.println("Driver chargé");
    			cn = (Connection) DriverManager.getConnection(url, login, pass);
    			System.out.println("Connecté");
    			st = (Statement) cn.createStatement();
    			String sql = "INSERT INTO `javadb` (`personnes`) VALUES ('" + personne + "')";
     
    			st.executeUpdate(sql);
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		finally
    		{
    			try
    			{
    				cn.close();
    				st.close();
    			} catch (SQLException e)
    			{
    				e.printStackTrace();
    			}
    		}
     
    	}
    }
    Je ne sais pas pourquoi j'obtiens cette erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
     
    Driver chargé
    com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 
     
    ** BEGIN NESTED EXCEPTION ** 
     
    java.net.UnknownHostException
    MESSAGE: db701563717.db.1and1.com
     
    STACKTRACE:
     
    java.net.UnknownHostException: db701563717.db.1and1.com
    	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    	at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source)
    	at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
    	at java.net.InetAddress.getAllByName0(Unknown Source)
    	at java.net.InetAddress.getAllByName(Unknown Source)
    	at java.net.InetAddress.getAllByName(Unknown Source)
    	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:163)
    	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:267)
    	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2739)
    	at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
    	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at game.Annagramme.main(Annagramme.java:24)
     
     
    ** END NESTED EXCEPTION **
     
     
     
    Last packet sent to the server was 11 ms ago.
    	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2814)
    	at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
    	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at game.Annagramme.main(Annagramme.java:24)
    Pouvez-vous m'aider ?

  2. #2
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Points : 9 529
    Points
    9 529
    Billets dans le blog
    1
    Par défaut
    La syntaxe de l'URL de connexion à une base MySQL est la suivante :

    jdbc:mysql://[host1][:port1][,[host2][:port2]]...[/[database]]


    Donc, dans ton cas, il cherche un hôte à l'adresse "db701563717.db.1and1.com".
    Si c'est le nom de ta DB, il faut rajouter un "/" sinon, si c'est bien le nom de ton hôte, vérifie qu'un ping db701563717.db.1and1.com abouti...
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Membre habitué
    Homme Profil pro
    Développeur de jeux vidéo
    Inscrit en
    Mai 2014
    Messages
    227
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur de jeux vidéo
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2014
    Messages : 227
    Points : 162
    Points
    162
    Par défaut
    J'ai déjà essayer avec toutes les syntaxes possibles. En local avec Wamp, j'arrive à me connecter, mais avec 1&1 impossible :/

    Pour le ping j'ai essayé, je n'ai aucune réponse, mais c'est peut être fait exprès de la part de chez 1&1. Donc bref en gros le problème vient de chez eux, pas de chez mon code :/

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème connexion BDD MySQL
    Par Toytoy00 dans le forum API standards et tierces
    Réponses: 4
    Dernier message: 08/12/2014, 10h52
  2. Problème de connexion BDD MySQL sous Android
    Par eloumghari.imane dans le forum API standards et tierces
    Réponses: 12
    Dernier message: 21/01/2014, 01h46
  3. [MySQL] Problème connexion bdd mysql
    Par boobs60 dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 11/03/2010, 08h48
  4. Problème connexion BDD MySql avec jdbc
    Par libery dans le forum JDBC
    Réponses: 6
    Dernier message: 27/05/2009, 12h25
  5. Problème de connexion BDD MySQL
    Par womannosky dans le forum JDBC
    Réponses: 12
    Dernier message: 28/04/2009, 11h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo