IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JDBC Java Discussion :

Mise à jour dans une base de données d'un checkbox via query


Sujet :

JDBC Java

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    468
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2009
    Messages : 468
    Points : 149
    Points
    149
    Par défaut Mise à jour dans une base de données d'un checkbox via query
    Bonjour la Communauté,

    Un msg d"erruer s'affiche au niveau de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ps.setString(10,txtjPanelLun1.getString());
    txtjpanelLun1 &tant un checkbox.

    quelqu"un pourrait-il m"aider ?


    Merci ç vous et une très bonne soirée.

    Habiler

    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
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    package decisions;
     
    import java.sql.*;
    import javax.swing.JOptionPane;
     
    public class AddDecisionsJFrame extends javax.swing.JFrame {
     
    Connection conn =null;
    ResultSet rs = null;
    PreparedStatement ps = null;
     
        /**
         * Creates new form DeciiJFrame
         */
        public AddDecisionsJFrame() {
            initComponents();
        }
     
     
     
        /**
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            TxtId = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            CmdSave = new javax.swing.JButton();
            jLabel2 = new javax.swing.JLabel();
            TxtDecId = new javax.swing.JTextField();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            TxtNumero = new javax.swing.JTextField();
            jLabel5 = new javax.swing.JLabel();
            TxtDatedec = new com.toedter.calendar.JDateChooser();
            jLabel6 = new javax.swing.JLabel();
            TxtDatedebut = new com.toedter.calendar.JDateChooser();
            jLabel7 = new javax.swing.JLabel();
            TxtDatefin = new com.toedter.calendar.JDateChooser();
            TxtMatr = new javax.swing.JTextField();
            TxtPourcent = new javax.swing.JTextField();
            jLabel8 = new javax.swing.JLabel();
            TxtAbsType = new javax.swing.JTextField();
            jLabel9 = new javax.swing.JLabel();
            txtjPanelLun1 = new javax.swing.JPanel();
            jCheckBox1 = new javax.swing.JCheckBox();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jLabel1.setText("Id");
     
            CmdSave.setText("Save record");
            CmdSave.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    CmdSaveMouseClicked(evt);
                }
            });
     
            jLabel2.setText("DecId");
     
            jLabel3.setText("Matricule");
     
            jLabel4.setText("Numero");
     
            jLabel5.setText("Date décision");
     
            TxtDatedec.setDateFormatString("dd-MMM-yyyy");
            TxtDatedec.setIcon(null);
     
            jLabel6.setText("Début de l'absence");
     
            TxtDatedebut.setDateFormatString("dd-MMM-yyyy");
            TxtDatedebut.setIcon(null);
     
            jLabel7.setText("Fin de l'absence");
     
            TxtDatefin.setDateFormatString("dd-MMM-yyyy");
            TxtDatefin.setIcon(null);
     
            jLabel8.setText("Pc d'activité");
     
            jLabel9.setText("Type d'absence");
     
            jCheckBox1.setText("Lundi");
     
            javax.swing.GroupLayout txtjPanelLun1Layout = new javax.swing.GroupLayout(txtjPanelLun1);
            txtjPanelLun1.setLayout(txtjPanelLun1Layout);
            txtjPanelLun1Layout.setHorizontalGroup(
                txtjPanelLun1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(txtjPanelLun1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jCheckBox1)
                    .addContainerGap(43, Short.MAX_VALUE))
            );
            txtjPanelLun1Layout.setVerticalGroup(
                txtjPanelLun1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(txtjPanelLun1Layout.createSequentialGroup()
                    .addComponent(jCheckBox1)
                    .addGap(0, 77, Short.MAX_VALUE))
            );
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(24, 24, 24)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jLabel9))
                            .addGap(18, 18, 18)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(TxtDatefin, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(TxtAbsType)
                                        .addComponent(TxtDatedebut, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(TxtPourcent, javax.swing.GroupLayout.Alignment.LEADING))
                                    .addGap(0, 0, Short.MAX_VALUE))))
                        .addComponent(jLabel5)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel4))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(35, 35, 35)
                                    .addComponent(CmdSave))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(62, 62, 62)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(TxtDatedec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(TxtNumero, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                                        .addComponent(TxtDecId, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                                        .addComponent(TxtId, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                                        .addComponent(TxtMatr))))))
                    .addGap(54, 54, 54)
                    .addComponent(txtjPanelLun1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(153, 153, 153))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(39, 39, 39)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel9)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(CmdSave))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(TxtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel1))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2)
                                .addComponent(TxtDecId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(TxtMatr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(8, 8, 8)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel5)
                                .addComponent(TxtDatedec, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(TxtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(3, 3, 3)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(TxtDatedebut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel6))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel7)
                                .addComponent(TxtDatefin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(TxtPourcent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel8))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(TxtAbsType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtjPanelLun1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addContainerGap())
            );
     
            pack();
        }// </editor-fold>                        
     
        private void CmdSaveMouseClicked(java.awt.event.MouseEvent evt) {                                     
    conn = Connect.ConnectDB();
    try{
     
    String sql = "Insert INTO Decisions (Id,DecId,Matr,Datedec,numero,Debut,Fin,Pourcent,AbsType,Lu1)VALUES(?,?,?,?,?,?,?,?,?,?)";
     
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setString(1,TxtId.getText()); // à voir si tu dois utiliser ps.setInt()
    ps.setString(2,TxtDecId.getText());
    ps.setString(3,TxtMatr.getText());
    ps.setDate(4,new java.sql.Date(TxtDatedec.getDate().getTime()));
    ps.setString(5,TxtNumero.getText());
    ps.setDate(6,new java.sql.Date(TxtDatedebut.getDate().getTime()));
    ps.setDate(7,new java.sql.Date(TxtDatefin.getDate().getTime()));
    ps.setString(8,TxtPourcent.getText());
    ps.setString(9,TxtAbsType.getText());
    ps.setString(10,txtjPanelLun1.getString());
    /*ps.execute();
           
        }                                    
    */
        ps.execute();
     
           {
        }                                    
              JOptionPane.showMessageDialog(null, "Saved");
                conn.close();
                }
             catch(Exception e)
    {
                JOptionPane.showMessageDialog(null, e);
                e.printStackTrace();
            }             
        }/**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
            //</editor-fold>
     
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new AddDecisionsJFrame().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify                     
        private javax.swing.JButton CmdSave;
        private javax.swing.JTextField TxtAbsType;
        private com.toedter.calendar.JDateChooser TxtDatedebut;
        private com.toedter.calendar.JDateChooser TxtDatedec;
        private com.toedter.calendar.JDateChooser TxtDatefin;
        private javax.swing.JTextField TxtDecId;
        private javax.swing.JTextField TxtId;
        private javax.swing.JTextField TxtMatr;
        private javax.swing.JTextField TxtNumero;
        private javax.swing.JTextField TxtPourcent;
        private javax.swing.JCheckBox jCheckBox1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JPanel txtjPanelLun1;
        // End of variables declaration                   
     
    }
    /*ps.execute();
           
           {
        }                                    
              JOptionPane.showMessageDialog(null, "Saved");
                conn.close();
                }
             catch(Exception e)
    {
                JOptionPane.showMessageDialog(null, e);
                e.printStackTrace();
            }             
        }/**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
            //</editor-fold>
     
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new AddDecisionsJFrame().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify                     
        private javax.swing.JButton CmdSave;
        private javax.swing.JTextField TxtAbsType;
        private com.toedter.calendar.JDateChooser TxtDatedebut;
        private com.toedter.calendar.JDateChooser TxtDatedec;
        private com.toedter.calendar.JDateChooser TxtDatefin;
        private javax.swing.JTextField TxtDecId;
        private javax.swing.JTextField TxtId;
        private javax.swing.JTextField TxtMatr;
        private javax.swing.JTextField TxtNumero;
        private javax.swing.JTextField TxtPourcent;
        private javax.swing.JCheckBox jCheckBox1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JPanel txtjPanelLun1;
        // End of variables declaration                   
     
    }

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.5 data exception: invalid character value for cast
    	at net.ucanaccess.jdbc.UcanaccessPreparedStatement.setString(UcanaccessPreparedStatement.java:701)
    	at decisions.AddDecisionsJFrame.CmdSaveMouseClicked(AddDecisionsJFrame.java:222)
    	at decisions.AddDecisionsJFrame.access$000(AddDecisionsJFrame.java:6)

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    468
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2009
    Messages : 468
    Points : 149
    Points
    149
    Par défaut
    Bonsoir à tous,

    J'ai modofié ma source avec la ligne suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ps.setString(10, (String) jCheckBoxLun1.getSelectedItem());
    mais il me met une erreur au niveau du getSelectedItem.
    Quelqu'un peut il m aider??

    Merci

    Habiler

  3. #3
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Bonjour,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
            txtjPanelLun1 = new javax.swing.JPanel();
            jCheckBox1 = new javax.swing.JCheckBox();
    Ton checkbox c'est jCheckBox1 mais pas txtjPanelLun1 qui est un JPanel. Pour voir s'il est coché ou non, utilise la méthode isSelected().

    A+.

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    468
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2009
    Messages : 468
    Points : 149
    Points
    149
    Par défaut
    Voici le code exact de mon programme. Il m'indique une erreur au niveau de .getSelectedItem.

    Je ne desire que transférer la valeur de mon checkbox dans une Bd access (champ yes/no). Donc qu'il soit selecté ou non.

    Je suis débutant et apprend par moi-même. D'ou ma nullité sorry.

    Habiler


    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
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    package decisions;
     
    import java.sql.*;
    import javax.swing.*;
    import java.awt.*;
     
     
    public class AddDecisionsJFrame extends javax.swing.JFrame {
     
    Connection conn =null;
    ResultSet rs = null;
    PreparedStatement ps = null;
     
        /**
         * Creates new form DeciiJFrame
         */
        public AddDecisionsJFrame() {
            initComponents();
        }
     
     
     
        /**
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            TxtId = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            CmdSave = new javax.swing.JButton();
            jLabel2 = new javax.swing.JLabel();
            TxtDecId = new javax.swing.JTextField();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            TxtNumero = new javax.swing.JTextField();
            jLabel5 = new javax.swing.JLabel();
            TxtDatedec = new com.toedter.calendar.JDateChooser();
            jLabel6 = new javax.swing.JLabel();
            TxtDatedebut = new com.toedter.calendar.JDateChooser();
            jLabel7 = new javax.swing.JLabel();
            TxtDatefin = new com.toedter.calendar.JDateChooser();
            TxtMatr = new javax.swing.JTextField();
            TxtPourcent = new javax.swing.JTextField();
            jLabel8 = new javax.swing.JLabel();
            TxtAbsType = new javax.swing.JTextField();
            jLabel9 = new javax.swing.JLabel();
            jCheckBoxLun1 = new javax.swing.JCheckBox();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
            getContentPane().add(TxtId, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 40, 91, -1));
     
            jLabel1.setText("Id");
            getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 42, 28, -1));
     
            CmdSave.setText("Save record");
            CmdSave.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    CmdSaveMouseClicked(evt);
                }
            });
            getContentPane().add(CmdSave, new org.netbeans.lib.awtextra.AbsoluteConstraints(106, 342, -1, -1));
     
            jLabel2.setText("DecId");
            getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 68, -1, -1));
            getContentPane().add(TxtDecId, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 65, 91, -1));
     
            jLabel3.setText("Matricule");
            getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 94, 47, -1));
     
            jLabel4.setText("Numero");
            getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 150, -1, 18));
            getContentPane().add(TxtNumero, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 150, 91, -1));
     
            jLabel5.setText("Date décision");
            getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 119, -1, -1));
     
            TxtDatedec.setDateFormatString("dd-MMM-yyyy");
            TxtDatedec.setIcon(null);
            getContentPane().add(TxtDatedec, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 120, 90, 20));
     
            jLabel6.setText("Début de l'absence");
            getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 182, -1, -1));
     
            TxtDatedebut.setDateFormatString("dd-MMM-yyyy");
            TxtDatedebut.setIcon(null);
            getContentPane().add(TxtDatedebut, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 180, 90, -1));
     
            jLabel7.setText("Fin de l'absence");
            getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 214, 98, -1));
     
            TxtDatefin.setDateFormatString("dd-MMM-yyyy");
            TxtDatefin.setIcon(null);
            getContentPane().add(TxtDatefin, new org.netbeans.lib.awtextra.AbsoluteConstraints(139, 208, 90, -1));
            getContentPane().add(TxtMatr, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 90, 91, -1));
            getContentPane().add(TxtPourcent, new org.netbeans.lib.awtextra.AbsoluteConstraints(139, 239, 90, -1));
     
            jLabel8.setText("Pc d'activité");
            getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 242, 98, -1));
            getContentPane().add(TxtAbsType, new org.netbeans.lib.awtextra.AbsoluteConstraints(139, 265, 90, -1));
     
            jLabel9.setText("Type d'absence");
            getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 265, -1, 20));
     
            jCheckBoxLun1.setText("Lundi");
            getContentPane().add(jCheckBoxLun1, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 260, -1, -1));
     
            pack();
        }// </editor-fold>                        
     
        private void CmdSaveMouseClicked(java.awt.event.MouseEvent evt) {                                     
    conn = Connect.ConnectDB();
    try{
     
     
    String sql = "Insert INTO Decisions (Id,DecId,Matr,Datedec,numero,Debut,Fin,Pourcent,AbsType,Lu1)VALUES(?,?,?,?,?,?,?,?,?,?)";
    PreparedStatement ps = conn.prepareStatement(sql);
     
    ps.setString(1,TxtId.getText()); // à voir si tu dois utiliser ps.setInt()
    ps.setString(2,TxtDecId.getText());
    ps.setString(3,TxtMatr.getText());
    ps.setDate(4,new java.sql.Date(TxtDatedec.getDate().getTime()));
    ps.setString(5,TxtNumero.getText());
    ps.setDate(6,new java.sql.Date(TxtDatedebut.getDate().getTime()));
    ps.setDate(7,new java.sql.Date(TxtDatefin.getDate().getTime()));
    ps.setString(8,TxtPourcent.getText());
    ps.setString(9,TxtAbsType.getText());
    //ps.setString(10,String.valueOf(jCheckBoxLun1.getText()));
    ps.setString(10, (String) jCheckBoxLun1.getSelectedItem());
     
    /*ps.execute();
           
        }                                    
    */
        ps.execute();
     
           {
        }                                    
              JOptionPane.showMessageDialog(null, "Saved");
                conn.close();
                }
             catch(Exception e)
    {
                JOptionPane.showMessageDialog(null, e);
                e.printStackTrace();
            }             
        }/**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(AddDecisionsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
            //</editor-fold>
     
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new AddDecisionsJFrame().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify                     
        private javax.swing.JButton CmdSave;
        private javax.swing.JTextField TxtAbsType;
        private com.toedter.calendar.JDateChooser TxtDatedebut;
        private com.toedter.calendar.JDateChooser TxtDatedec;
        private com.toedter.calendar.JDateChooser TxtDatefin;
        private javax.swing.JTextField TxtDecId;
        private javax.swing.JTextField TxtId;
        private javax.swing.JTextField TxtMatr;
        private javax.swing.JTextField TxtNumero;
        private javax.swing.JTextField TxtPourcent;
        private javax.swing.JCheckBox jCheckBoxLun1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        // End of variables declaration                   
     
    }

  5. #5
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Citation Envoyé par HABILER Voir le message
    Il m'indique une erreur au niveau de .getSelectedItem.
    Citation Envoyé par andry.aime Voir le message
    Pour voir s'il est coché ou non, utilise la méthode isSelected().
    Parce qu'un JCheckBox n'a pas de méthode getSelectedItem, tu ne peux pas utiliser quelque chose qui n'existe pas. isSelected retourne une valeur booléenne (true, false), fait donc attention avec le setString de ton preparedStatement si ça correspond bien au type de colonne de ta base.

    A+.

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    468
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2009
    Messages : 468
    Points : 149
    Points
    149
    Par défaut
    Bon après-midi,

    Suis-je obligé de passer par par un isSelected.

    Quelqu'un aurait-il un exemple pour mon cas. Je n'en sors pas ?

    Habiler

  7. #7
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ps.setObject(10, jCheckBoxLun1.isSelected());

  8. #8
    Modérateur
    Avatar de MasterMbg
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2011
    Messages
    719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2011
    Messages : 719
    Points : 1 493
    Points
    1 493
    Par défaut
    Citation Envoyé par HABILER Voir le message
    Quelqu'un aurait-il un exemple pour mon cas. Je n'en sors pas ?
    Habiler
    Salut,

    Je te propose ce petit exemple.

    imagine que tu aies un champ "sexe" dans ta table. Pour permettre à l'utilisateur de renseigner son sexe sur ton formulaire d'enregistrement, tu prévois deux JCheckBox nommés respectivement checkMasculin et checkFeminin.

    La question qui se pose, comment connaître le choix que l'utilisateur a fait?

    Pour répondre à cette question, tu peux déclarer une variable "sexe_utilisateur" de type String :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    String sexe_utilisateur;
    ensuite, tu pourras tester si l'un des checkbox est coché en utilisant la méthode isChecked et si ça renvoie true, selon le cas tu affectes le texte associé au checkbox coché. Enfin de comptes, tu utilises la variable "sexe" pour enregistrer dans la base de données.

    Je ne te passe pas le code Parce que je réponds via mon smartphone, désolé.

    Christian Djo Mbangala.,
    Plus tu apprends sérieusement, plus tu te rapproches d'un savoir noble. Une chose est certaine, les difficultés ne s'écarteront de ton chemin...

    Tu es nouveau dans le développement Android, la page des COURS est là pour te faciliter la vie
    Tu peux trouver la réponse à ta question dans la FAQ
    Retrouvez mon tutoriel sur la consommation des services web SOAP
    Pense à voter positivement en appuyant sur en bas à droite de la réponse qui t'a donné une piste de solution.

Discussions similaires

  1. Mise à jour d'une base de données
    Par JeanMarc_T2k dans le forum Services
    Réponses: 1
    Dernier message: 01/02/2008, 22h48
  2. Réponses: 7
    Dernier message: 13/08/2007, 13h15
  3. Rentrer la date du jour dans une base de données
    Par Guguslefun dans le forum ASP.NET
    Réponses: 4
    Dernier message: 04/06/2007, 14h05
  4. probleme de virgule dans la mise à jour d'une base de donnée
    Par KAF dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 24/12/2005, 02h18
  5. mise à jour d'une base de données
    Par flo83 dans le forum ASP
    Réponses: 6
    Dernier message: 12/06/2005, 20h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo