Problème d'une mise à jour de table
Bonsoir , j'ai besoin de faire un UPDATE d'une table à partir de java mais j'ai pas peut être (ou surement ) bien connu la requête adéquate , en effet je veux soustraire le un nombre entier à un contenu d'une colonne (entier aussi ) voici le code que j'ai essayé mais ca marche pas , j'ai une erreur dans sql :
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
| try(){
String a=Combo1.getSelectedItem().toString();
int b =(Integer)jSpinner1.getValue();
String c = ((JTextField)jcal.getDateEditor().getUiComponent()).getText();
int f = -b ;
if(evt.getSource()==btn_cmd)
{
try{
Connection conn;
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/stage","root","admin");
Statement pst=conn.createStatement();
Statement pst2=conn.createStatement();
pst.executeUpdate("INSERT INTO Commande(Nom_article,Qté_commande,Date_commande) values ('"+a+"','"+b+"','"+c+"')");
pst.executeUpdate("UPDATE Commande SET Qté_dispo =Qté dispo +"+f+" WHERE Nom_article='"+a+"'");
JOptionPane.showMessageDialog(null , "Commande envoyé","Accusé !",
JOptionPane.INFORMATION_MESSAGE);
setVisible(false) ;
}catch (Exception e)
{
System.out.println(e);
}
}
} |