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 :

Problème d'ajout à la base


Sujet :

JDBC Java

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    3
    Détails du profil
    Informations personnelles :
    Âge : 35
    Localisation : Tunisie

    Informations forums :
    Inscription : Novembre 2009
    Messages : 3
    Points : 1
    Points
    1
    Par défaut Problème d'ajout à la base
    salut a tous,j'ai un prb d'ajout des donnees a ma base acces,j'ai besoin de votre aide svp,voila le code complet:

    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
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    package javaapplication2;
     
    import java.util.Map;
    import java.util.Properties;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.text.DateFormat;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    import java.text.ParseException;
     
     
     
    public class Test extends JFrame implements ActionListener{
        static String nom1,prenom1,ncin1,ninsc1,sexe1,datenaiss1,niveauSco1,etatcivile1,daterec1,datecont1,salaire1,classe1,degre1,regime1,titre1,partie1,arrondissement1,article1,paragraphe1,sousp1;
        JLabel hr = new JLabel();
        JLabel heure = new JLabel("Heure:  ");
        JLabel ncin = new JLabel ("Num CIN:  " );
        JTextField Tncin = new JTextField();
        JLabel ninsc = new JLabel("Num Inscription:    ");
        JTextField Tninsc = new JTextField();
        JLabel n = new JLabel("Nom:");
        JTextField Tn = new JTextField();
        JLabel pr = new JLabel("Prenom:");
        JTextField Tp = new JTextField();
        JLabel niv = new JLabel("Niveau scolaire:");
        JTextField Tniv = new JTextField();
        JLabel datenais = new JLabel("Date naissance:");
        JTextField Tdatenais = new JTextField();
        JLabel sexe = new JLabel("sexe:");
        JComboBox Cbsex = new JComboBox(); 
        JLabel etatciv = new JLabel("Etat civile:");
        JComboBox Cbetatciv = new JComboBox();
        JLabel daterec = new JLabel("Date recrutement:");
        JTextField Tdaterec = new JTextField();
        JLabel classe = new JLabel("Classe: ");
        JComboBox Cbclasse = new JComboBox();
        JLabel degre = new JLabel("Degré:");
        JComboBox Cbdegre = new JComboBox();
        JLabel regime = new JLabel("Regime:");
        JTextField Tregime = new JTextField();
        JLabel salaire = new JLabel("Salaire:");
        JTextField Tsalaire = new JTextField();
        JLabel titre = new JLabel("Titre:");
        JTextField Ttitre = new JTextField();
        JLabel partie = new JLabel("Partie:");
        JTextField Tpartie = new JTextField();
        JLabel arrondissement = new JLabel("Arrondissement:");
        JComboBox Cbarrondissement = new JComboBox();
        JLabel datecont = new JLabel("Date contrat:");
        JTextField Tdatecont = new JTextField();
        JLabel article = new JLabel("Article:");
        JTextField Tarticle = new JTextField();
        JLabel parag = new JLabel("Paragraphe:");
        JTextField Tparag = new JTextField();
        JLabel sousparag = new JLabel("Sous-paragraphe:");
        JTextField Tsousp = new JTextField();
        JLabel vide = new JLabel();
        JComboBox Cbvide = new JComboBox();
        JButton ajouter = new JButton("Ajouter");
        JButton modifier = new JButton("Modifier");
        JButton supprimer = new JButton("Supprimer");
        JButton recherche = new JButton("Recherche");
        JButton quitter = new JButton("Quitter");
        JButton annuler = new JButton("Annuler");
        JButton next = new JButton(">");
        JButton previous = new JButton("<");
     
     
     
    public Test(){
        this.getContentPane().setLayout(new GridLayout(12,4));
        JPanel p = new JPanel();
        p.setLayout(new GridLayout(3,4));
        p.add(ncin);
        p.add(Tncin);
        p.add(ninsc);
        p.add(Tninsc);
        p.add(n);
        p.add(Tn);
        p.add(pr);
        p.add(Tp);
        p.add(niv);
        p.add(Tniv);
        p.add(datenais);
        p.add(Tdatenais);
        this.getContentPane().add(p);
     
        JPanel p1 = new JPanel();
        p1.setLayout(new GridLayout(3,4));
        p1.add(sexe);
        p1.add(Cbsex);
        p1.add(etatciv);
        p1.add(Cbetatciv);
        p1.add(classe);
        p1.add(Cbclasse);
        p1.add(degre);
        p1.add(Cbdegre);
        p1.add(arrondissement);
        p1.add(Cbarrondissement);
        p1.add(vide);
        p1.add(Cbvide);
        this.getContentPane().add(p1);
     
        JPanel p2 = new JPanel();
        p2.setLayout(new GridLayout(3,4));
        p2.add(regime);
        p2.add(Tregime);
        p2.add(salaire);
        p2.add(Tsalaire);
        p2.add(article);
        p2.add(Tarticle);
        p2.add(parag);
        p2.add(Tparag);
        p2.add(sousparag);
        p2.add(Tsousp);
        p2.add(partie);
        p2.add(Tpartie);
        this.getContentPane().add(p2);
     
        JPanel p3 = new JPanel();
        p3.setLayout(new GridLayout(2,4));
        p3.add(daterec);
        p3.add(Tdaterec);
        p3.add(titre);
        p3.add(Ttitre);
        p3.add(datecont);
        p3.add(Tdatecont);
        p3.add(heure);
        p3.add(hr);
        this.getContentPane().add(p3);
     
      //panel des bouttons:
        JPanel p4 = new JPanel();
        p4.setLayout(new GridLayout(1,4));
        p4.add(ajouter);
        p4.add(modifier);
        p4.add(recherche);
        p4.add(annuler);
        this.getContentPane().add(p4);
     
        JPanel p5 = new JPanel();
        p5.setLayout(new GridLayout(1,4));
        p5.add(supprimer);
        p5.add(next);
        p5.add(previous);
        p5.add(quitter);
        this.getContentPane().add(p5);
     
    //listes des Combobox
        Cbsex.addItem("MALE");
        Cbsex.addItem("FEMELE");
        Cbetatciv.addItem("Célibataire");
        Cbetatciv.addItem("Marié");
        Cbetatciv.addItem("Divorsé");
        Cbarrondissement.addItem("");
        Cbarrondissement.addItem("Arrondissement financier");
        Cbarrondissement.addItem("Arrondissement des ressources en eau");
        Cbarrondissement.addItem("Arrondissement personnel");
        Cbclasse.addItem("A");
        Cbclasse.addItem("B");
        Cbclasse.addItem("C");
        Cbdegre.addItem("1");
        Cbdegre.addItem("2");
        Cbdegre.addItem("3");
     
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.pack();
        this.setVisible(true);
        this.setTitle("Gestion des Contractuels");
    //ajout des ecouteurs:
        ajouter.addActionListener(this);
        modifier.addActionListener(this);
        recherche.addActionListener(this); 
        annuler.addActionListener(this);
        supprimer.addActionListener(this);
        quitter.addActionListener(this);
        next.addActionListener(this);
        previous.addActionListener(this);
     
     
    }
    public void actionPerformed(ActionEvent e) {
            JButton src=(JButton)e.getSource();
     
            if(src==quitter){
                System.exit(0);
            }
     
     
            if(src==annuler){
                Tn.setText("");
                Tp.setText("");
                Tncin.setText("");
                Tninsc.setText("");
                Tniv.setText("");
                Tdatenais.setText("");
                Tdaterec.setText("");
                Tregime.setText("");
                Tsalaire.setText("");
                Ttitre.setText("");
                Tpartie.setText("");
                Tdatecont.setText("");
                Tarticle.setText("");
                Tparag.setText("");
                Tsousp.setText("");
            }
           if(src==ajouter){
            String Sn = Tn.getText();
            String Sp = Tp.getText();
            String Scin = Tncin.getText();
            String Snins = Tninsc.getText();
            String Snivs = Tniv.getText();
            String Sdatenais=Tdatenais.getText();
            String Sdaterec=Tdaterec.getText();
            String Sdatecont=Tdatecont.getText();
            Object Osex = Cbsex.getSelectedItem();
            Object Oclasse = Cbclasse.getSelectedItem();
            Object Oetat = Cbetatciv.getSelectedItem();
            Object Odegre = Cbdegre.getSelectedItem();
            String Spartie = Tpartie.getText();
            String Sregime = Tregime.getText();
            String Stitre = Ttitre.getText();
            Object Oarrond = Cbarrondissement.getSelectedItem();
            String Sarticle = article.getText();
            String Sparag = Tparag.getText();
            String Ssousp = Tsousp.getText();
            if (Tninsc.getText().length() != 8) {
                JOptionPane.showMessageDialog(null, "Inserez 8 chiffres:Num Inscr", "Information", JOptionPane.ERROR_MESSAGE);
            }
            if (Tncin.getText().length() != 8) {
                JOptionPane.showMessageDialog(null, "Inserez 8 chiffres:Num CINS", "Information", JOptionPane.ERROR_MESSAGE);
            }
     
                //Connexion a la base
                String req="insert into personnel values('+Sn','+Sdatenais+','+Sdatenrec+','+Sdatecont+', +Sp+,'+Sncin+','+Snins+','+Snivs+','+Sregime+','+Ssalaire+','+Stitre+','+Spartie+','+Sarticle+','+Sparag+','+Ssousp+','+Osex+','+Oetat+','+Oclasse+','+Oarrond+','Odegre+')";
                try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection Con=DriverManager.getConnection("Mes documents/Personnel");
                Statement st = Con.createStatement();
                int x = st.executeUpdate(req);
                st.close();
                Con.close();
                }
                catch(ClassNotFoundException x){
                    System.out.println("Erreur");
                }
     
                catch(SQLException g){
                JOptionPane.showMessageDialog(null, "Erreur requete","Alert", JOptionPane.ERROR_MESSAGE);
     
                }          
    }
           if(src==supprimer){
     
               String req="delete from employe";
                try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection Con=DriverManager.getConnection("Mes documents/Personnel");
                Statement st = Con.createStatement();
                int x = st.executeUpdate(req);
                st.close();
                Con.close();
                }
                catch(ClassNotFoundException x){
                    System.out.println("Erreur");
                }
     
                catch(SQLException g){
                JOptionPane.showMessageDialog(null, "Erreur requete","Alert", JOptionPane.ERROR_MESSAGE);
     
                }  
    }
     
          if(src==modifier){
              try {
                Connection c = new Connection() {
     
                        @Override
                        public Statement createStatement() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public PreparedStatement prepareStatement(String sql) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public CallableStatement prepareCall(String sql) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public String nativeSQL(String sql) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void setAutoCommit(boolean autoCommit) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public boolean getAutoCommit() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void commit() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void rollback() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void close() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public boolean isClosed() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public DatabaseMetaData getMetaData() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void setReadOnly(boolean readOnly) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public boolean isReadOnly() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void setCatalog(String catalog) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public String getCatalog() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void setTransactionIsolation(int level) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public int getTransactionIsolation() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public SQLWarning getWarnings() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void clearWarnings() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public Map<String, Class<?>> getTypeMap() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void setHoldability(int holdability) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public int getHoldability() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public Savepoint setSavepoint() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public Savepoint setSavepoint(String name) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void rollback(Savepoint savepoint) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void releaseSavepoint(Savepoint savepoint) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public Clob createClob() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public Blob createBlob() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public NClob createNClob() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public SQLXML createSQLXML() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public boolean isValid(int timeout) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void setClientInfo(String name, String value) throws SQLClientInfoException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public void setClientInfo(Properties properties) throws SQLClientInfoException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public String getClientInfo(String name) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public Properties getClientInfo() throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public <T> T unwrap(Class<T> iface) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
     
                        @Override
                        public boolean isWrapperFor(Class<?> iface) throws SQLException {
                            throw new UnsupportedOperationException("Not supported yet.");
                        }
                    };
                c.connecte();
                ResultSet rs = c.res("Update nom1,prenom1,ncin1,ninsc1,degre1,salaire1,datenaiss1,classe1,article1 from employe");
                if (rs.next()) {
     
                    nom1 = rs.getString("Tnom");
                    prenom1 = rs.getString("Tprenom");
                    ncin1 = rs.getString("Tncin");
                    ninsc1 = rs.getString("Tninsc");
                    degre1 = rs.getString("degre");
                    salaire1 = rs.getString("salaire");
                    datenaiss1 = rs.getString("date_naiss");
                    classe1 = rs.getString("Tclasse");
                    article1 = rs.getString("Tarticle");
                    niveauSco1 = rs.getString("Tniv");
                    partie1 = rs.getString("Tpartie");
                    paragraphe1 = rs.getString("Tparag");
                    titre1 = rs.getString("Ttitre");
     
     
          }
     
              }    
                catch(SQLException g){
                JOptionPane.showMessageDialog(null, "Erreur requete","Alert", JOptionPane.ERROR_MESSAGE);
     
                } 
     
    }
    }
     
     
        public static void main(String[] args) {
            new Test();
        }
     
        }

  2. #2
    Modérateur
    Avatar de kolodz
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    2 211
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 211
    Points : 8 318
    Points
    8 318
    Billets dans le blog
    52
    Par défaut
    Bonjour,

    je vous conseil très vivement d'utiliser la balise CODE qui est à votre disposition.
    Voici votre code dans cette balise :
    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
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    package javaapplication2;
     
    import java.util.Map;
    import java.util.Properties;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.text.DateFormat;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    import java.text.ParseException;
     
     
     
    public class Test extends JFrame implements ActionListener{
    static String nom1,prenom1,ncin1,ninsc1,sexe1,datenaiss1,niveauSco1,etatcivile1,daterec1,datecont1,salaire1,classe1,degre1,regime1,titre1,partie1,arrondissement1,article1,paragraphe1,sousp1;
    JLabel hr = new JLabel();
    JLabel heure = new JLabel("Heure: ");
    JLabel ncin = new JLabel ("Num CIN: " );
    JTextField Tncin = new JTextField();
    JLabel ninsc = new JLabel("Num Inscription: ");
    JTextField Tninsc = new JTextField();
    JLabel n = new JLabel("Nom:");
    JTextField Tn = new JTextField();
    JLabel pr = new JLabel("Prenom:");
    JTextField Tp = new JTextField();
    JLabel niv = new JLabel("Niveau scolaire:");
    JTextField Tniv = new JTextField();
    JLabel datenais = new JLabel("Date naissance:");
    JTextField Tdatenais = new JTextField();
    JLabel sexe = new JLabel("sexe:");
    JComboBox Cbsex = new JComboBox();
    JLabel etatciv = new JLabel("Etat civile:");
    JComboBox Cbetatciv = new JComboBox();
    JLabel daterec = new JLabel("Date recrutement:");
    JTextField Tdaterec = new JTextField();
    JLabel classe = new JLabel("Classe: ");
    JComboBox Cbclasse = new JComboBox();
    JLabel degre = new JLabel("Degré:");
    JComboBox Cbdegre = new JComboBox();
    JLabel regime = new JLabel("Regime:");
    JTextField Tregime = new JTextField();
    JLabel salaire = new JLabel("Salaire:");
    JTextField Tsalaire = new JTextField();
    JLabel titre = new JLabel("Titre:");
    JTextField Ttitre = new JTextField();
    JLabel partie = new JLabel("Partie:");
    JTextField Tpartie = new JTextField();
    JLabel arrondissement = new JLabel("Arrondissement:");
    JComboBox Cbarrondissement = new JComboBox();
    JLabel datecont = new JLabel("Date contrat:");
    JTextField Tdatecont = new JTextField();
    JLabel article = new JLabel("Article:");
    JTextField Tarticle = new JTextField();
    JLabel parag = new JLabel("Paragraphe:");
    JTextField Tparag = new JTextField();
    JLabel sousparag = new JLabel("Sous-paragraphe:");
    JTextField Tsousp = new JTextField();
    JLabel vide = new JLabel();
    JComboBox Cbvide = new JComboBox();
    JButton ajouter = new JButton("Ajouter");
    JButton modifier = new JButton("Modifier");
    JButton supprimer = new JButton("Supprimer");
    JButton recherche = new JButton("Recherche");
    JButton quitter = new JButton("Quitter");
    JButton annuler = new JButton("Annuler");
    JButton next = new JButton(">");
    JButton previous = new JButton("<");
     
     
     
    public Test(){
    this.getContentPane().setLayout(new GridLayout(12,4));
    JPanel p = new JPanel();
    p.setLayout(new GridLayout(3,4));
    p.add(ncin);
    p.add(Tncin);
    p.add(ninsc);
    p.add(Tninsc);
    p.add(n);
    p.add(Tn);
    p.add(pr);
    p.add(Tp);
    p.add(niv);
    p.add(Tniv);
    p.add(datenais);
    p.add(Tdatenais);
    this.getContentPane().add(p);
     
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(3,4));
    p1.add(sexe);
    p1.add(Cbsex);
    p1.add(etatciv);
    p1.add(Cbetatciv);
    p1.add(classe);
    p1.add(Cbclasse);
    p1.add(degre);
    p1.add(Cbdegre);
    p1.add(arrondissement);
    p1.add(Cbarrondissement);
    p1.add(vide);
    p1.add(Cbvide);
    this.getContentPane().add(p1);
     
    JPanel p2 = new JPanel();
    p2.setLayout(new GridLayout(3,4));
    p2.add(regime);
    p2.add(Tregime);
    p2.add(salaire);
    p2.add(Tsalaire);
    p2.add(article);
    p2.add(Tarticle);
    p2.add(parag);
    p2.add(Tparag);
    p2.add(sousparag);
    p2.add(Tsousp);
    p2.add(partie);
    p2.add(Tpartie);
    this.getContentPane().add(p2);
     
    JPanel p3 = new JPanel();
    p3.setLayout(new GridLayout(2,4));
    p3.add(daterec);
    p3.add(Tdaterec);
    p3.add(titre);
    p3.add(Ttitre);
    p3.add(datecont);
    p3.add(Tdatecont);
    p3.add(heure);
    p3.add(hr);
    this.getContentPane().add(p3);
     
    //panel des bouttons:
    JPanel p4 = new JPanel();
    p4.setLayout(new GridLayout(1,4));
    p4.add(ajouter);
    p4.add(modifier);
    p4.add(recherche);
    p4.add(annuler);
    this.getContentPane().add(p4);
     
    JPanel p5 = new JPanel();
    p5.setLayout(new GridLayout(1,4));
    p5.add(supprimer);
    p5.add(next);
    p5.add(previous);
    p5.add(quitter);
    this.getContentPane().add(p5);
     
    //listes des Combobox
    Cbsex.addItem("MALE");
    Cbsex.addItem("FEMELE");
    Cbetatciv.addItem("Célibataire");
    Cbetatciv.addItem("Marié");
    Cbetatciv.addItem("Divorsé");
    Cbarrondissement.addItem("");
    Cbarrondissement.addItem("Arrondissement financier");
    Cbarrondissement.addItem("Arrondissement des ressources en eau");
    Cbarrondissement.addItem("Arrondissement personnel");
    Cbclasse.addItem("A");
    Cbclasse.addItem("B");
    Cbclasse.addItem("C");
    Cbdegre.addItem("1");
    Cbdegre.addItem("2");
    Cbdegre.addItem("3");
     
    this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    this.pack();
    this.setVisible(true);
    this.setTitle("Gestion des Contractuels");
    //ajout des ecouteurs:
    ajouter.addActionListener(this);
    modifier.addActionListener(this);
    recherche.addActionListener(this);
    annuler.addActionListener(this);
    supprimer.addActionListener(this);
    quitter.addActionListener(this);
    next.addActionListener(this);
    previous.addActionListener(this);
     
     
    }
    public void actionPerformed(ActionEvent e) {
    JButton src=(JButton)e.getSource();
     
    if(src==quitter){
    System.exit(0);
    }
     
     
    if(src==annuler){
    Tn.setText("");
    Tp.setText("");
    Tncin.setText("");
    Tninsc.setText("");
    Tniv.setText("");
    Tdatenais.setText("");
    Tdaterec.setText("");
    Tregime.setText("");
    Tsalaire.setText("");
    Ttitre.setText("");
    Tpartie.setText("");
    Tdatecont.setText("");
    Tarticle.setText("");
    Tparag.setText("");
    Tsousp.setText("");
    }
    if(src==ajouter){
    String Sn = Tn.getText();
    String Sp = Tp.getText();
    String Scin = Tncin.getText();
    String Snins = Tninsc.getText();
    String Snivs = Tniv.getText();
    String Sdatenais=Tdatenais.getText();
    String Sdaterec=Tdaterec.getText();
    String Sdatecont=Tdatecont.getText();
    Object Osex = Cbsex.getSelectedItem();
    Object Oclasse = Cbclasse.getSelectedItem();
    Object Oetat = Cbetatciv.getSelectedItem();
    Object Odegre = Cbdegre.getSelectedItem();
    String Spartie = Tpartie.getText();
    String Sregime = Tregime.getText();
    String Stitre = Ttitre.getText();
    Object Oarrond = Cbarrondissement.getSelectedItem();
    String Sarticle = article.getText();
    String Sparag = Tparag.getText();
    String Ssousp = Tsousp.getText();
    if (Tninsc.getText().length() != 8) {
    JOptionPane.showMessageDialog(null, "Inserez 8 chiffres:Num Inscr", "Information", JOptionPane.ERROR_MESSAGE);
    }
    if (Tncin.getText().length() != 8) {
    JOptionPane.showMessageDialog(null, "Inserez 8 chiffres:Num CINS", "Information", JOptionPane.ERROR_MESSAGE);
    }
     
    //Connexion a la base
    String req="insert into personnel values('+Sn','+Sdatenais+','+Sdatenrec+','+Sdatecont+', +Sp+,'+Sncin+','+Snins+','+Snivs+','+Sregime+','+Ssalaire+','+Stitre+','+Spartie+','+Sarticle+','+Sparag+','+Ssousp+','+Osex+','+Oetat+','+Oclasse+','+Oarrond+','Odegre+')";
    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection Con=DriverManager.getConnection("Mes documents/Personnel");
    Statement st = Con.createStatement();
    int x = st.executeUpdate(req);
    st.close();
    Con.close();
    }
    catch(ClassNotFoundException x){
    System.out.println("Erreur");
    }
     
    catch(SQLException g){
    JOptionPane.showMessageDialog(null, "Erreur requete","Alert", JOptionPane.ERROR_MESSAGE);
     
    }
    }
    if(src==supprimer){
     
    String req="delete from employe";
    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection Con=DriverManager.getConnection("Mes documents/Personnel");
    Statement st = Con.createStatement();
    int x = st.executeUpdate(req);
    st.close();
    Con.close();
    }
    catch(ClassNotFoundException x){
    System.out.println("Erreur");
    }
     
    catch(SQLException g){
    JOptionPane.showMessageDialog(null, "Erreur requete","Alert", JOptionPane.ERROR_MESSAGE);
     
    }
    }
     
    if(src==modifier){
    try {
    Connection c = new Connection() {
     
    @Override
    public Statement createStatement() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public PreparedStatement prepareStatement(String sql) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public CallableStatement prepareCall(String sql) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public String nativeSQL(String sql) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void setAutoCommit(boolean autoCommit) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public boolean getAutoCommit() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void commit() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void rollback() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void close() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public boolean isClosed() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public DatabaseMetaData getMetaData() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void setReadOnly(boolean readOnly) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public boolean isReadOnly() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void setCatalog(String catalog) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public String getCatalog() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void setTransactionIsolation(int level) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public int getTransactionIsolation() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public SQLWarning getWarnings() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void clearWarnings() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public Map<String, Class<?>> getTypeMap() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void setHoldability(int holdability) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public int getHoldability() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public Savepoint setSavepoint() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public Savepoint setSavepoint(String name) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void rollback(Savepoint savepoint) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void releaseSavepoint(Savepoint savepoint) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public Clob createClob() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public Blob createBlob() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public NClob createNClob() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public SQLXML createSQLXML() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public boolean isValid(int timeout) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void setClientInfo(String name, String value) throws SQLClientInfoException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public void setClientInfo(Properties properties) throws SQLClientInfoException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public String getClientInfo(String name) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public Properties getClientInfo() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public <T> T unwrap(Class<T> iface) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
     
    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
    }
    };
    c.connecte();
    ResultSet rs = c.res("Update nom1,prenom1,ncin1,ninsc1,degre1,salaire1,datenaiss1,classe1,article1 from employe");
    if (rs.next()) {
     
    nom1 = rs.getString("Tnom");
    prenom1 = rs.getString("Tprenom");
    ncin1 = rs.getString("Tncin");
    ninsc1 = rs.getString("Tninsc");
    degre1 = rs.getString("degre");
    salaire1 = rs.getString("salaire");
    datenaiss1 = rs.getString("date_naiss");
    classe1 = rs.getString("Tclasse");
    article1 = rs.getString("Tarticle");
    niveauSco1 = rs.getString("Tniv");
    partie1 = rs.getString("Tpartie");
    paragraphe1 = rs.getString("Tparag");
    titre1 = rs.getString("Ttitre");
     
     
    }
     
    }
    catch(SQLException g){
    JOptionPane.showMessageDialog(null, "Erreur requete","Alert", JOptionPane.ERROR_MESSAGE);
     
    }
     
    }
    }
     
     
    public static void main(String[] args) {
    new Test();
    }
     
    }
    Maintenant, il serai agréable de savoir ce qui pose problème dans votre "ajout" à votre base de donnée Access.
    Expliquez-nous ce que vous voulez faire et quel et l'erreur qui vous bloque.

    Cordialement,
    Patrick Kolodziejczyk.
    Si une réponse vous a été utile pensez à
    Si vous avez eu la réponse à votre question, marquez votre discussion
    Pensez aux FAQs et aux tutoriels et cours.

  3. #3
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    3
    Détails du profil
    Informations personnelles :
    Âge : 35
    Localisation : Tunisie

    Informations forums :
    Inscription : Novembre 2009
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    apres le saisie des donnees dans les zones de texte et les combobox,les donnees s'enregistre dans la base en cliquant sur le bouton "ajouter",j'ai fais une exception SQLException qui affiche un msg "erreur requete".mon prb c ke ce msg s'affiche en cliquant sur le bouton"ajouter" ainsi que les information ne s'enregistre pas dans la base.

  4. #4
    Modérateur
    Avatar de kolodz
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    2 211
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 211
    Points : 8 318
    Points
    8 318
    Billets dans le blog
    52
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    String req="insert into personnel values('+Sn','+Sdatenais+','+Sdatenrec+','+Sdatecont+', +Sp+,'+Sncin+','+Snins+','+Snivs+','+Sregime+','+Ssalaire+','+Stitre+','+Spartie+','+Sarticle+','+Sparag+','+Ssousp+','+Osex+','+Oetat+','+Oclasse+','+Oarrond+','Odegre+')";
    D'après moi, votre requête n'est pas valide. Et devrait avoir une tête comme cela :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    String req="insert into personnel values("+Sn+","+Sdatenais+","+Sdatenrec+","+Sdatecont+", "+Sp+","+Sncin+","+Snins+","+Snivs+","+Sregime+","+Ssalaire+","+Stitre+","+Spartie+","+Sarticle+","+Sparag+","+Ssousp+","+Osex+","+Oetat+","+Oclasse+","+Oarrond+","Odegre+")";
    Après, cela peux aussi venir de l'un des paramètres.
    D'ailleurs cela ne m'étonnerai même pas qu'il y en ai une aussi à ce niveau.

    Cordialement,
    Patrick Kolodziejczyk.
    Si une réponse vous a été utile pensez à
    Si vous avez eu la réponse à votre question, marquez votre discussion
    Pensez aux FAQs et aux tutoriels et cours.

  5. #5
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    3
    Détails du profil
    Informations personnelles :
    Âge : 35
    Localisation : Tunisie

    Informations forums :
    Inscription : Novembre 2009
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    ça reste une erreur manque de ; dans la requete j sais pas ou exactement!
    est ce que le rest du code du bouton "ajouter","supprimer","modifier" est correcte s'il vous plait?

  6. #6
    Modérateur
    Avatar de kolodz
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    2 211
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 211
    Points : 8 318
    Points
    8 318
    Billets dans le blog
    52
    Par défaut
    Aucune idée !
    Si une réponse vous a été utile pensez à
    Si vous avez eu la réponse à votre question, marquez votre discussion
    Pensez aux FAQs et aux tutoriels et cours.

  7. #7
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Recommandation de type quasi impérative, arrêter d'utiliser des Statement et utiliser des PreparedStatement à la place. Ca évite beaucoup de problèmes dus aux paramètres.

    Dans le cas présent:

    exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    //Préparation de la requête, les ? sont utilisé par java pour déterminer l'emplacement des paramètres
    PreparedStatement p = con.prepareStatement("insert into MA_TABLE (COL1, COL2, COL3, COL4) values (?,?,?,?)");
    //spécification de la valeur des paramètres
    p.setString(1,"toto");
    p.setInt(2,45);
    p.setDate(3,new java.sql.Date(new java.util.Date().getTime());
    p.setString(4,"Hello");
    //exécution de la requête
    p.executeUpdate();
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    281
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 281
    Points : 321
    Points
    321
    Par défaut
    A mon avis, c'est la requête qui ne va pas.
    Pour commencer, il faut mettre des " au lieu de ' pour sortir du String (je ne sais pas si je suis clair).
    Ensuite il n'y a pas de ";" à la fin de la requete sql. Est-ce normal ?

  9. #9
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 39
    Points : 51
    Points
    51
    Par défaut
    Salut,

    Je crois que les valeurs a insérer doivent être entourées de '. De plus, pour une question de facilité de maintenance et d'ajout de colonnes dans la base de données il vaut mieux donner les noms des colonnes de la base.

    Au final, ca donnerait un truc comme ca:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    String req="insert into personnel (date, maValeur) values('"+dateAInseree+"','"+valeurAInseree+"')";
    J'espere que ca aidera.
    A+

  10. #10
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    281
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 281
    Points : 321
    Points
    321
    Par défaut
    Citation Envoyé par braxxe Voir le message
    Salut,

    Je crois que les valeurs a insérer doivent être entourées de '. De plus, pour une question de facilité de maintenance et d'ajout de colonnes dans la base de données il vaut mieux donner les noms des colonnes de la base.

    Au final, ca donnerait un truc comme ca:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    String req="insert into personnel (date, maValeur) values('"+dateAInseree+"','"+valeurAInseree+"')";
    J'espere que ca aidera.
    A+
    Sans oublier le ";" à la fin de l'instruction.

  11. #11
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 39
    Points : 51
    Points
    51
    Par défaut
    Sans oublier le ";" à la fin de l'instruction.
    Ben quoi, il y est mon ;

Discussions similaires

  1. Réponses: 0
    Dernier message: 22/03/2012, 16h30
  2. tOracleSCD, problème d'ajout dans la base
    Par NTeeN dans le forum Développement de jobs
    Réponses: 2
    Dernier message: 04/06/2009, 11h43
  3. Problème d'ajout dans base Access
    Par iziwas dans le forum VBA Access
    Réponses: 4
    Dernier message: 10/02/2009, 12h05
  4. problème d'ajout base accès en vb.net
    Par dokko dans le forum VB.NET
    Réponses: 1
    Dernier message: 25/04/2007, 21h23
  5. Réponses: 1
    Dernier message: 27/06/2006, 13h47

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