Bonjour,
J'ai un problème qui je voudrais demander votre aide. en fait j'ai un formulaire en jave qui permet à l'utilisateur de commander un produit à partir d'une liste déroulante qui contient tout les noms de produits stockés dans la table sql et introduire la quantité désiré. une fois l'utilisateur clique sur le bouton valide la quantité demandé va être éliminer de la quantité en stock.
Voici le code que j'ai proposé.
voici l'erreur affiché:
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 public void actionPerformed(ActionEvent evt) { // TODO Auto-generated method stub if(evt.getSource()==b1){ int x=Integer.parseInt(text1.getText()); String a= (String) liste.getSelectedItem(); System.out.println(a); try { Class.forName("com.mysql.jdbc.Driver"); laConnection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/application?useSSL=false","boutheina","30071986"); String sql = "select quantite from produit where designation=?"; PreparedStatement statement = laConnection.prepareStatement(sql); statement.setObject(1, a); try(ResultSet Rs = statement.executeQuery()) { while(Rs.next()){ if(Rs.getInt("quantite")>=x){ JOptionPane.showMessageDialog(null, "Your Command is validated, " + "you can move to the payement", "InformationMessage", JOptionPane.INFORMATION_MESSAGE); try { Class.forName("com.mysql.jdbc.Driver"); laConnection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/application?useSSL=false","boutheina","30071986"); String sql1="Update produit set quantite= quantite-'x' where designation=?"; PreparedStatement statement1 = laConnection.prepareStatement(sql1); statement1.setObject(1, a); if(statement1.executeUpdate()!=1){ JOptionPane.showMessageDialog(null, "la modification de la quantité n'est pas effectué ", "Error Message", JOptionPane.ERROR_MESSAGE);} else{JOptionPane.showMessageDialog(null, "la modification de la quantité est effectué", "Information Message", JOptionPane.INFORMATION_MESSAGE); } } catch (Exception e) { System.out.print("impossible de se connecter à la base"); e.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "An error appears in the inscription: the ID of the product already exist ", "Error Message", JOptionPane.ERROR_MESSAGE);} } } catch (Exception e) { System.out.print("impossible de se connecter à la base dans la requete update"); e.printStackTrace(); } } catch (Exception e) { System.out.print("impossible de se connecter à la base"); e.printStackTrace();} }
impossible de se connecter à la basecom.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'x'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3964)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
at Distributeur.Order.actionPerformed(Order.java:167)
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$000(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)
Partager