Bonjour. J'ai un problème de sauvegarde des données d'un Jtable dans une base de données MySQL. L'application permet d'établir un échéancier de paiement d'un emprunt. Dans cet échéancier, j'ai 8 colonnes dont 7 de type Int et1 autre de type String (C'est la colonne de la date) . Le Jtable fonction bien mais je n'arrive à le sauvegarder dans la base de données.
Le problème est que lorsque je veut enrégistrer les données dans la BDD je recoir une erreur de type (Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer).
voici mon code.
Voila l'intégralité du message d'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
41
42 Connection conn=SingletonConnection.getConnection(); try { PreparedStatement ps=conn.prepareStatement ("insert into ECHEANCIER values (?,?,?,?,?,?,?,?,?,?,?)"); for (int i = 0; i < model.getRowCount(); i++) { for (int j = 0; j < model.getColumnCount(); j++) { int o=(Integer) model.getValueAt(i, j); /*c2=(Integer) model.getValueAt(i, 2); c3=(Integer) model.getValueAt(i, 3); c4=(Integer) model.getValueAt(i, 4); c5=(Integer) model.getValueAt(i, 5); c6=(Integer) model.getValueAt(i, 6); c7=(Integer) model.getValueAt(i, 7);*/ String Sdate=(String) model.getValueAt(i, 1); DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); Date date = formatter.parse(Sdate); java.sql.Date sqlDate = new java.sql.Date(date.getTime()); ps.setInt(1, pre); ps.setString(2,txtCodeCli.getText()); ps.setString(3, "R"+model.getValueAt(i, 0)); ps.setDate(4, sqlDate); ps.setDouble(j+2, o); /*ps.setDouble(5, c2); ps.setDouble(6, c3); ps.setDouble(7, c4); ps.setDouble(8, c5); ps.setDouble(9, c6); ps.setDouble(10, c7);*/ ps.setDate(11, sqlDate); } } ps.execute(); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); }
Aidez moi s'il vous plais.
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 Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer at MetierPresentation.FrameEcheancier$3.actionPerformed(FrameEcheancier.java:439) 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$500(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$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$JavaSecurityAccessImpl.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$JavaSecurityAccessImpl.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