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 :

Erreur "java.lang.NullPointerException" SQL serveur ResultSet


Sujet :

JDBC Java

  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2011
    Messages : 13
    Par défaut Erreur "java.lang.NullPointerException" SQL serveur ResultSet
    Bonjour,

    J'ai un soucis sur un logiciel que je développe au travail.
    Voici le code 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
    40
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at Design.RecupEtallonnage(Design.java:289)
    	at Design.InsertionReleveBDD(Design.java:271)
    	at Design$2.actionPerformed(Design.java:107)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$200(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    La ligne où pose le soucis est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ResultSet rs=bdd.ExecuterRequeteLecture(requete);
    Voici ma classe : BDD
    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
    50
    51
    52
    public class BDD {
     
    	public Connection con;
     
    	public BDD(String chaineConnexion) throws ClassNotFoundException, InstantiationException, IllegalAccessException
    	{
    		try{
    	        String url = chaineConnexion;
    	        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
    	        con = DriverManager.getConnection(url);
    	        if(con != null)
    	        {
    	        	javax.swing.JOptionPane.showMessageDialog(null, "Connexion Réussie");
    	        }
    	        else
    	        {
    	        	javax.swing.JOptionPane.showMessageDialog(null, "Connexion echoué");
    	        }
     
    	    } catch(SQLException se){
    	        System.out.println("SQL exception: " + se.getMessage());
    	    }
     
    	}
     
    	public ResultSet ExecuterRequeteLecture(String requete)
    	{
    		try{
    		    Statement stmt = con.createStatement();
    		    ResultSet rs = stmt.executeQuery(requete);
    		    System.out.println(rs.toString());
    		    return rs;
    		} catch(SQLException se){
    		    System.out.println("SQL exception: " + se.getMessage());
    		    return null;
    		}
    	}
     
    	public boolean ExecuterRequeteInsert(String requete)
    	{
    		try{
    			Statement stmt = con.createStatement();
    			return stmt.execute(requete);
    		}
    		catch( SQLException se)
    		{
    			System.out.println("SQL exception : " +se.getMessage());
    			return false;
    		}
    	}
     
    }
    Ma requête est bonne et la connexion à BDD est bien ouverte. Je ne comprend pas pourquoi RS serait null

    Merci d'avance pour votre aide précieuse

  2. #2
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 713
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 713
    Par défaut
    J'ai bien une idée.
    Tu peux poster le code de la requête ?
    Labor improbus omnia vincit un travail acharné vient à bout de tout - Ambroise Paré (1510-1590)

    Consulter sans modération la FAQ ainsi que les bons ouvrages : http://jmdoudoux.developpez.com/cours/developpons/java/

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2011
    Messages : 13
    Par défaut
    Je viens de trouver l'erreur , j'avais pas initialiser la variable bdd.

    Merci quand même de ton aide

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

Discussions similaires

  1. Réponses: 9
    Dernier message: 31/05/2011, 10h40
  2. erreur compilation java.lang.NullPointerException
    Par muslim1987 dans le forum JDBC
    Réponses: 6
    Dernier message: 26/06/2008, 09h16
  3. Erreur exception java.lang.NullPointerException
    Par geol99 dans le forum Langage
    Réponses: 2
    Dernier message: 14/06/2007, 20h24
  4. erreur de java.lang.NullPointerException
    Par vince351 dans le forum Langage
    Réponses: 1
    Dernier message: 25/03/2007, 12h29

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