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

Développement Web en Java Discussion :

Connexion à la base de données


Sujet :

Développement Web en Java

  1. #1
    Futur Membre du Club
    Femme Profil pro
    etudient
    Inscrit en
    Août 2014
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudient

    Informations forums :
    Inscription : Août 2014
    Messages : 9
    Points : 7
    Points
    7
    Par défaut Connexion à la base de données
    Bonjour
    j'ai une application web en jee je travaille sous eclipse indigo mon problème c'est que j'arrive pas a etablir la connexion a ma base de donnée qui est crée sous phpmyadmin malgré que j'ai ajouté mysql-connector-java-5.1.18-bin.jar au dossier Web-Inf\lib et je l'ai ajouter dans Project > Properties > Java Build Path j'ai toujous cette exception :
    java.lang.ClassNotFoundException: com.mysql.jdbc.driver
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Unknown Source)
    	at com.eniso.project.core.metier.SingletonConnection.<clinit>(SingletonConnection.java:12)
    	at com.eniso.project.core.metier.MetierImp.getEvenementParC(MetierImp.java:15)
    	at com.eniso.project.core.metier.TestMetier.main(TestMetier.java:12)
    Exception in thread "main" java.lang.NullPointerException
    	at com.eniso.project.core.metier.MetierImp.getEvenementParC(MetierImp.java:17)
    	at com.eniso.project.core.metier.TestMetier.main(TestMetier.java:12)
    alors si quelqu'un pouvait m'orienter sur les solutions que je dois implémenter j'en serais très soulagé
    bonne journée.

  2. #2
    Membre expérimenté Avatar de Nico02
    Homme Profil pro
    Developpeur Java/JEE
    Inscrit en
    Février 2011
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Developpeur Java/JEE
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2011
    Messages : 728
    Points : 1 622
    Points
    1 622
    Par défaut
    Peux tu nous montrer le code Java qui charge ce driver ?

    Voir les cours et tutoriels Java et la FAQ Java pour te mettre sur la voie.

    Cdt.

  3. #3
    Futur Membre du Club
    Femme Profil pro
    etudient
    Inscrit en
    Août 2014
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudient

    Informations forums :
    Inscription : Août 2014
    Messages : 9
    Points : 7
    Points
    7
    Par défaut
    merci pour votre réponse voila mon 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
    package com.eniso.project.core.metier;
     
    import java.sql.DriverManager;
    import java.sql.*;
    import com.mysql.jdbc.Driver;
    import com.mysql.jdbc.Connection;
     
    public class SingletonConnection {
    	private static Connection connection;
    	static {
    		try{
    			Class.forName("com.mysql.jdbc.Driver");
    			connection=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:8080/db_mvc_event","root","");
     
    		}catch(Exception e){
    			e.printStackTrace();
    		}
     
    	}
    	public static Connection getConnection(){
    		return connection;
    	}
     
    }
    j'ai changé com.mysql.jdbc.driver par com.mysql.jdbc.Driver mais j'ai eu ces erreurs.pouvez vous m'aider


    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
    48
    49
    com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 
     
    ** BEGIN NESTED EXCEPTION ** 
     
    java.net.ConnectException
    MESSAGE: Connection refused: connect
     
    STACKTRACE:
     
    java.net.ConnectException: Connection refused: connect
    	at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    	at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    	at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    	at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    	at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    	at java.net.PlainSocketImpl.connect(Unknown Source)
    	at java.net.SocksSocketImpl.connect(Unknown Source)
    	at java.net.Socket.connect(Unknown Source)
    	at java.net.Socket.connect(Unknown Source)
    	at java.net.Socket.<init>(Unknown Source)
    	at java.net.Socket.<init>(Unknown Source)
    	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
    	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
    	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
    	at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
    	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at com.eniso.project.core.metier.SingletonConnection.<clinit>(SingletonConnection.java:13)
    	at com.eniso.project.core.metier.MetierImp.getEvenementParC(MetierImp.java:15)
    	at com.eniso.project.core.metier.TestMetier.main(TestMetier.java:12)
     
     
    ** END NESTED EXCEPTION **
     
     
     
    Last packet sent to the server was 2 ms ago.
    	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847)
    	at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
    	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at com.eniso.project.core.metier.SingletonConnection.<clinit>(SingletonConnection.java:13)
    	at com.eniso.project.core.metier.MetierImp.getEvenementParC(MetierImp.java:15)
    	at com.eniso.project.core.metier.TestMetier.main(TestMetier.java:12)
    Exception in thread "main" java.lang.NullPointerException
    	at com.eniso.project.core.metier.MetierImp.getEvenementParC(MetierImp.java:17)
    	at com.eniso.project.core.metier.TestMetier.main(TestMetier.java:12)

  4. #4
    Membre expérimenté Avatar de Nico02
    Homme Profil pro
    Developpeur Java/JEE
    Inscrit en
    Février 2011
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Developpeur Java/JEE
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2011
    Messages : 728
    Points : 1 622
    Points
    1 622
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    connection=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:8080/db_mvc_event","root","");
    Il n'y a pas de mot de passe pour ton utilisateur root ?

    Vérifie aussi que le nom de ta base de donnée soit exactement celui que tu as mis dons ton SGBD.

    As-tu un firewall qui pourrait bloquer la connexion ?

    Es-tu sur que ton mySql écoute le port 8080 ? Car par défaut il me semble qu'il écoute le port 3306.

  5. #5
    Futur Membre du Club
    Femme Profil pro
    etudient
    Inscrit en
    Août 2014
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudient

    Informations forums :
    Inscription : Août 2014
    Messages : 9
    Points : 7
    Points
    7
    Par défaut
    merci Nico02
    mon problème est résolu lorsque j'ai changé mon code comme ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    try{
    			Class.forName("com.mysql.jdbc.Driver");
    			connection=(Connection) DriverManager.getConnection("jdbc:mysql://localhost/db_mvc_event","root","");
     
    		}catch(Exception e){
    			e.printStackTrace();
    		}

Discussions similaires

  1. [JDBC][MySQL] Connexion à la base de données
    Par El Saigneur dans le forum JDBC
    Réponses: 8
    Dernier message: 04/08/2005, 14h52
  2. ERREUR DE CONNEXION à une base de donnée ACCESS protégée
    Par unionriton dans le forum Bases de données
    Réponses: 4
    Dernier message: 09/05/2005, 10h35
  3. Delphi Connexion à une base de donnée distante par TCP/IP
    Par viecel dans le forum Bases de données
    Réponses: 1
    Dernier message: 12/01/2005, 20h19
  4. Echec lors de la connexion à la base de données.
    Par mclown dans le forum PostgreSQL
    Réponses: 8
    Dernier message: 27/10/2004, 00h36
  5. Réponses: 3
    Dernier message: 29/03/2004, 19h02

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