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:
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:
ResultSet rs=bdd.ExecuterRequeteLecture(requete);
Voici ma classe : BDD
Code:
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