Bonjour tout le monde
je rencontre un problème de requete sql en java depuis presque deux semaine et je n'arrive vraiment pas à y trouver de solution.
j'ai deux classe chacune doit mette à jour une table dans ma base de données dans la première classe j'ai le code suivant qui fonctionne bien
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| Save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Cette méthode ne sera appelée que pour les évènements sur le bouton monBouton.
// chaine de connexion
final String url = "jdbc:mysql://localhost:3306/rescue";
Connection con = null;
Statement requete = null;
ResultSet resultat1 = null;
String val1 = (String) Mpay.getSelectedItem();
String val2 = (String) Stat.getSelectedItem();
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url,"root","amine");
// création de la rquête
requete = con.createStatement();
// exécution de la requête
// récupération des identifiants de connexion
int resultat = requete.executeUpdate("update Interventionexter set DATE_INTEREXT='"+Dateexter.getText()+"', DATE_FACTURATION='"+Dfacture.getText()+"', PROBLEMATIQUE='"+Pb.getText()+"', DESCRIPTION='"+Descrip.getText()+"', COUT='"+Ct.getText()+"', MODE_PAIEMENT='"+val1+"', EXTSTATUT='"+val2+"' where N_INTEREXT = "+Interventionexter.Nvenexter+"");
JOptionPane.showMessageDialog(null,"Votre intervention a été bien modifiée" );
// Labeltest.setText(Numclient+ Nomclient + Ntelclient);
Fclient Fclient = new Fclient();
Fclient.setVisible(true);
dispose();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (Exception e3) {
e3.printStackTrace();
}
finally {
try {con.close();
requete.close();
resultat1.close();
}
catch(final SQLException e1) {e1.printStackTrace();}
}
}
}); |
dans la deuxième classe dont j'ai le gros problème j'ai le code suivant:
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
| Save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final String url = "jdbc:mysql://localhost:3306/rescue";
Connection con = null;
Statement requete = null;
String val1 = (String) Mpay.getSelectedItem();
String val2 = (String) Stat.getSelectedItem();
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url,"root","amine");
requete = con.createStatement();
int resultat = requete.executeUpdate("update Interventioninter set DATE_ENTREE='"+Denter.getText()+"', DATE_INTERINT='"+Dateinter.getText()+"', DATE_FACTURATION='"+Dfacture.getText()+"', DATE_SORTIE= '"+Dsortie.getText()+"', PROBLEMATIQUE='"+Pb.getText()+"', DESCRIPTION='"+Descrip.getText()+"', COUT='"+Ct.getText()+"', MODE_PAIEMENT= '"+val1+"', INTSTATUT= '"+val2+"' where N_INTERINT="+Interventioninter.Nveninter+"");
JOptionPane.showMessageDialog(null,"Votre intervention a été bien modifiée" );
Fclient Fclient = new Fclient();
Fclient.setVisible(true);
dispose(); |
et je recupére l'erreur suivant
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALIMENTATION', COUT='70.00', MODE_PAIEMENT= 'Espèce', INTSTATUT= 'En cours' wher' at line 1
alors quand je mets preparedStatement au lieu de Statment je recupére bien un message comme quoi les datas sont bien modifiées mais quand je vérifie dans la base de données je trouve que aucune modification n'a été faite
bon je recupère quand meme un message en bas d'eclipse
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
| Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Finterventionintermodify$1.actionPerformed(Finterventionintermodify.java:274)
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.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) |
merci de me repondre le plus vite possible
Partager