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 lors d'insertion (INSERT INTO) d'information


Sujet :

JDBC Java

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut Problème lors d'insertion (INSERT INTO) d'information
    Bonjour !
    Si quelqu'un peut m'aider SVP ! J'ai créé un formulaire en java swing contenant plusieurs champs Texte ainsi que ComboBox ! Tout est bien lors de l'execution on me dit qu'il existe un problème dans le INSERT INTO !!
    Voilà mon morceau de code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    private void BtnenregistrerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAjouterActionPerformed
        try{
     
       //if (ev.getSource()==Btnenregistrer)
       //{ 
    	   S.executeUpdate("INSERT INTO entreprise(N_de_dossier,Nom(gerant),Prenom(gerant),Nom(cogerant),Prenom(cogerant),CIN(gerant),CIN(cogerant),Date_de_naissance(gerant),Date_de_naissance(cogerant),Denomination,Adresse,Localite) VALUES ("+TxtDoss.getText()+",'"+TxtNom.getText()+"','"+TxtPrenom.getText()+"','"+TxtNom1.getText()+"','"+TxtPrenom1.getText()+"','"+TxtCIN1.getText()+"','"+TxtCIN2.getText()+"','"+TxtDate1.getText()+"','"+TxtDate2.getText()+"','"+TxtAdresse.getText()+"','"+ville.getSelectedItem()+"');");
     
    	   JOptionPane.showMessageDialog(null,"Inscription ajoutée ");
     
     
      } catch(Exception e){
           JOptionPane.showMessageDialog(null," Erreur de la nouvelle inscription \n"+e.getMessage()); 
      }
    }

  2. #2
    Membre émérite
    Avatar de olivier.pitton
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juin 2012
    Messages
    355
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Hauts de Seine (Île de France)

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

    Informations forums :
    Inscription : Juin 2012
    Messages : 355
    Points : 2 814
    Points
    2 814
    Par défaut
    Tes colonnes ont des noms ... étranges. Je pense que tu devrais mettre les vrais noms de colonnes. De plus, pense à mettre ce code entre la balise code et d'afficher l'exception.

  3. #3
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    Se sont les vrais noms de colonnes !Puisque je travaille avec access !! Pouvez vous m'éclaircie davantage SVP !

  4. #4
    Membre du Club
    Inscrit en
    Juillet 2010
    Messages
    58
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 58
    Points : 52
    Points
    52
    Par défaut
    Je te conseille d’utiliser des requêtes préparées.

    http://java.developpez.com/faq/jdbc/...paredstatement


    String query="INSERT INTO entreprise(N_de_dossier,Nom(gerant),Prenom(gerant),Nom(cogerant),Prenom(cogerant),CIN(gerant),CIN(cogerant),Date_de_naissance(gerant),Date_de_naissance(cogerant),Denomination,Adresse,Localite) VALUES (?,?,?,...);

    java.sql.PreparedStatement s = cnx.prepareStatement(query);
    s.setString(1, TxtDoss.getText());
    s.setString(2,TxtNom.getText());
    ....
    s.executeUpdate();
    Pense à vérifier, la longueur des champs des ' dans la zone de texte etc... etc... .
    Faudrait voir le message d'erreur, pour plus de détail.
    Voilà j'espère t'avoir aidé

  5. #5
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    Merci d'avoir m'aider J'ai essayé mais en vain !! On m'écrit : Erreur de la nouvelle inscription ! null !! Je ne sais pas encore où est la faute dans mon code :
    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
    String query="INSERT INTO entreprise(N_de_dossier,Nom(gerant),Prenom(gerant),Nom(cogerant),Prenom(cogerant),CIN(gerant),CIN(cogerant),Date_de_naissance(gerant),Date_de_naissance(cogerant),Denomination,Adresse,Localite) VALUES (?,?,?,?,?,?,?,?,?,?,?,?);)";
        	        Date date = new Date(0);
        			java.sql.PreparedStatement S = C.prepareStatement(query);
        			S.setString(1, TxtDoss.getText());
        			S.setString(2,TxtNom.getText());
        			S.setString(3, TxtPrenom.getText());
        			S.setString(4, TxtNom1.getText());
        			S.setString(5, TxtPrenom1.getText());
        			S.setObject(6, TxtCIN1.getText());
        			S.setString(7, TxtCIN2.getText());
        			S.setDate(8, date.valueOf("+TxtDate1.getText()+"));
        			S.setDate(9, date.valueOf("+TxtDate2.getText()+"));
        			S.setString(10, TxtDenom.getText());
        			S.setString(11, TxtAdresse.getText());
        		    S.setString(12, (String) ville.getSelectedItem());
        			S.executeUpdate();
     
    	            JOptionPane.showMessageDialog(null,"Inscription ajoutée ");
     
     
      } catch(Exception e){
           JOptionPane.showMessageDialog(null," Erreur de la nouvelle inscription \n"+e.getMessage()); 
      }
    }

  6. #6
    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 sql : Sélectionner tout - Visualiser dans une fenêtre à part
    N_de_dossier,`Nom(gerant)`,`Prenom(gerant)`,`Nom(cogerant)`,`Prenom(cogerant)`,`CIN(gerant)`,`CIN(cogerant)`,`Date_de_naissance(gerant)`,`Date_de_naissance(cogerant)`,Denomination,Adresse,Localite

    Tu peux aussi nous montrer les messages d'erreur?

    Sinon, je pense que tu dois renommer les noms de ton colonnes par Nom_gerant.

    A+.

  7. #7
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Citation Envoyé par RimyAD Voir le message
    Merci d'avoir m'aider J'ai essayé mais en vain !! On m'écrit : Erreur de la nouvelle inscription ! null !! Je ne sais pas encore où est la faute dans mon code :
    Ben vu que tu n'affiche pas la stacktrace complète de ton erreur mais juste "null" tout ce qu'on peux te dire, c'est que t'as un truc null dans ton code quelque part. Affiche la stacktrace complète.



    Et comme le dit andry.aime, il faut mettre des ' ' ou des ` ` autour des noms de colonne utilisant des caractères spécifique au language SQL.

  8. #8
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    j'ai fait exactement comme vous m'avez dit :

    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
    private void BtnenregistrerActionPerformed(java.awt.event.ActionEvent evt) {
     
        try{
    String query="INSERT INTO entreprise(`N_de_dossier`,`Nom_gerant`,`Prenom_gerant`,`Nom_cogerant`,`Prenom_cogerant`,`CIN_gerant`,`CIN_cogerant`,`Date_de_naissance_gerant`,`Date_de_naissance_cogerant`,`Denomination`,`Adresse`,`Localite`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?);)";
        	        Date date = new Date(0);
        			java.sql.PreparedStatement S = C.prepareStatement(query);
        			S.setString(1, TxtDoss.getText());
        			S.setString(2,TxtNom.getText());
        			S.setString(3, TxtPrenom.getText());
        			S.setString(4, TxtNom1.getText());
        			S.setString(5, TxtPrenom1.getText());
        			S.setInt(6, Integer.parseInt(TxtCIN1.getText()));
        			S.setInt(7, Integer.parseInt(TxtCIN2.getText()));
        			S.setDate(8, date.valueOf("+TxtDate1.getText()+"));
        			S.setDate(9, date.valueOf("+TxtDate2.getText()+"));
        			S.setString(10, TxtDenom.getText());
        			S.setString(11, TxtAdresse.getText());
        		    S.setString(12, (String) ville.getSelectedItem());
        			S.executeUpdate();
     
    	            JOptionPane.showMessageDialog(null,"Inscription ajoutée ");
     
     
      } catch(Exception e){
           JOptionPane.showMessageDialog(null," Erreur de la nouvelle inscription \n"+e.getMessage()); 
      }
    }
    On m'affiche : erreur de la nouvelle inscription : For input string "" !!

  9. #9
    Membre averti
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    230
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 230
    Points : 310
    Points
    310
    Par défaut
    Bonjour,

    Ce qu'il t'est demandé, c'est de faire un copier-coller complet de l'erreur (toutes les lignes).

  10. #10
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    Pouvez vous m'éclaircir davantage ?? Comment faire un copier coller de l'erreur ??

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

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    faire un e.printStackTrace() dans ton bloc catch, en copier le résultat et le coller dans un message.
    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.

  12. #12
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    Toujours en vain les amis !!

  13. #13
    Membre averti
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    230
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 230
    Points : 310
    Points
    310
    Par défaut
    Tu as ajouté une ligne

    après la ligne

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    JOptionPane.showMessageDialog(null," Erreur de la nouvelle inscription \n"+e.getMessage());
    ?

    Si oui, tu devrais avoir un message d'erreur détaillé dans ta console, il faudrait le donner.

  14. #14
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    On m'écrit : erreur for input string "" je dois rendre mon travaille la semaine prochaine ! et je bloque sur cette partie !! Aidez moi SVP Voilà tout le code :

    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
    import javax.swing.*;
     
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Date;
    import java.sql.PreparedStatement;
     
    import java.io.*;
    import java.sql.*;
    import java.lang.*;
    import java.sql.*;
     
    public class Inscription extends JFrame {
    Connection C;
    Statement S;
    ResultSet r;
     
    private JButton Btnenregistrer = new JButton("Enregistrer");
    private JButton Btnsuivant = new JButton("Suivant >>");
    private JLabel LblNom = new JLabel("Nom (gérant) : ");
    private JLabel LblNom1 = new JLabel("Nom (co-gérant) : ");
    private JLabel LblPrenom = new JLabel("Prénom (gérant) : ");
    private JLabel LblPrenom1 = new JLabel("Prénom (co-gérant) : ");
    private JLabel LblCIN1 = new JLabel("CIN (gérant) : ");
    private JLabel LblCIN2 = new JLabel("CIN (co-gérant) : ");
    private JLabel LblDateNaiss = new JLabel("Date de Naissance : ");
    private JLabel Lbldate = new JLabel ("Date de naissance (co-gérant) : ");
    private JLabel LblDenom = new JLabel("Dénomination : ");
    private JLabel LblAdresse = new JLabel("Adresse : ");
    private JLabel Lblville = new JLabel("Localité : ");
    private JLabel LblDoss = new JLabel("Dossier N° : ");
     
    private JTextField TxtNom  = new JTextField(15);
    private JTextField TxtNom1 = new JTextField(15);
    private JTextField TxtPrenom  = new JTextField(50);
    private JTextField TxtPrenom1 = new JTextField(50);
    private JTextField TxtCIN1  = new JTextField(10);
    private JTextField TxtCIN2 = new JTextField(10);
    private JTextField TxtDenom = new JTextField(15);
    private JTextField TxtAdresse  = new JTextField(50);
    private JTextField TxtDate1 = new JTextField(15);
    private JTextField TxtDate2 = new JTextField(15);
    private JComboBox ville = new  JComboBox();
    private JTextField TxtDoss = new JTextField(10);
     
    Inscription (){
                 Container c = getContentPane();
                 c.setLayout(null);
                 c.setForeground(Color.gray);
                 ville.setPreferredSize(new Dimension(300, 300));
                 ville.addItem("--");
                 ville.addItem("MEKNES");
                 ville.addItem("SEBAA AIOUN");
                 ville.addItem("AIN TAOUJDATE");
                 ville.addItem("MOULAY DRISS ZERHOUN");
                 ville.addItem("OUISLANE");
                 ville.addItem("BOUFKRANE");
                 ville.addItem("AÏN JAMAA");
                 ville.addItem("AÏN KARMA");
                 ville.addItem("AÏN ORMA");
                 ville.addItem("AÏT OULLAL");
                 ville.addItem("CHARQOUA");
                 ville.addItem("DAR OM SOLTANE");
                 ville.addItem("DKHISSA");
                 ville.addItem("KARMET BEN SALEM");
                 ville.addItem("MAJJATE");
                 ville.addItem("LM'HAYA");
                 ville.addItem("M'RHASSIYINE");
                 ville.addItem("N'ZALAT BNI AMAR");
                 ville.addItem("OUALILI");
                 ville.addItem("OUED JDIDA");
                 ville.addItem("OUED ROMMANE");
                 ville.addItem("SIDI ABDELLAH EL KHAYAT");
                 ville.addItem("SIDI SLIMANE MOUL LKIFANE");
    this.setTitle("Nouvelle inscription");
                    this.setSize(800, 750);
                    //this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
                    addWindowListener(new java.awt.event.WindowAdapter() {
                        public void windowOpened(java.awt.event.WindowEvent ev) {
                            formWindowOpened(ev);
                        }
                    });
                    this.setLocationRelativeTo(null);
                    this.setContentPane(c);
                    this.setVisible(true);
     
                    LblNom.setBounds(new Rectangle(30, 40, 150, 25));
                    TxtNom.setBounds(new Rectangle(250, 40, 150, 25));
                    LblPrenom.setBounds(new Rectangle(30, 80, 150, 40));
                    TxtPrenom.setBounds(new Rectangle(250, 90, 150, 25));
                    LblNom1.setBounds(new Rectangle(30, 130, 180, 40));
                    TxtNom1.setBounds(new Rectangle(250, 140, 150, 25));
                    LblPrenom1.setBounds(new Rectangle (30, 179, 150, 40 ));
                    TxtPrenom1.setBounds(new Rectangle(250, 189, 150, 25));
                    LblCIN1.setBounds(new Rectangle(30, 220, 150, 40));
                    TxtCIN1.setBounds(new Rectangle(250,230, 150, 25));
                    LblCIN2.setBounds(new Rectangle(30,260,150,40));
                    TxtCIN2.setBounds(new Rectangle(250,265,150,25));
                    LblDateNaiss.setBounds(new Rectangle(30, 300, 125, 40));
                    Lbldate.setBounds(new Rectangle(30,340,250,40));
                    TxtDate1.setBounds(new Rectangle(250,305,150,25));
                    TxtDate2.setBounds(new Rectangle(250,350,150,25));
    LblDenom.setBounds(new Rectangle(30, 380, 200, 40));
                    TxtDenom.setBounds(new Rectangle(250, 390, 180, 25));
                    LblAdresse.setBounds(new Rectangle(30, 439, 300, 40));
                    TxtAdresse.setBounds(new Rectangle(250, 440, 300, 50));
                    Lblville.setBounds(new Rectangle(30, 520, 125, 40));
                    ville.setBounds(new Rectangle(250, 520, 183, 25));
                    LblDoss.setBounds(new Rectangle(30, 575, 125, 40));
                    TxtDoss.setBounds(new Rectangle(250, 580, 120, 25));
                    Btnsuivant.setBounds(new Rectangle(570, 650, 120, 24));
                    Btnenregistrer.setBounds(new Rectangle(50, 650, 100, 24));
     
                    c.add(LblNom);
                    c.add(TxtNom);
                    c.add(TxtPrenom);
                     c.add(LblPrenom);
                     c.add(LblNom1);
                     c.add(TxtNom1);
                     c.add(LblPrenom1);
                     c.add(TxtPrenom1);
                     c.add(LblCIN1);
                     c.add(TxtCIN1);
                     c.add(LblCIN2);
                     c.add(TxtCIN2);
    c.add(Lbldate);
                     c.add(LblDateNaiss);
                     c.add(TxtDate1);
                     c.add(TxtDate2);
                     c.add(LblDenom);
                     c.add(TxtDenom);
                     c.add(LblAdresse);
                     c.add(TxtAdresse);
                     c.add(ville);
                     c.add(Lblville);
                     c.add(LblDoss);
                     c.add(TxtDoss);
                    c.add(Btnenregistrer);
                    c.add(Btnsuivant);
    Btnenregistrer.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent ev) {
                        	BtnenregistrerActionPerformed(ev);
                        }
                    });
                    Btnsuivant.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent ev) {
                        	BtnsuivantActionPerformed(ev);
                        }
                    });
    	}
    private void formWindowOpened(java.awt.event.WindowEvent ev) {//GEN-FIRST:event_formWindowOpened
        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            C = DriverManager.getConnection("jdbc:odbc:stage");
            S = C.createStatement();
    	} catch (Exception e){   
    		JOptionPane.showMessageDialog(null,"erreur de connexion\n"+e.getMessage());
        }
     }
    private void BtnenregistrerActionPerformed(java.awt.event.ActionEvent ev) {//GEN-FIRST:event_btnAjouterActionPerformed
        try{
    String query="INSERT INTO entreprise(`N_de_dossier`,`Nom_gerant`,`Prenom_gerant`,`Nom_cogerant`,`Prenom_cogerant`,`CIN_gerant`,`CIN_cogerant`,`Date_de_naissance_gerant`,`Date_de_naissance_cogerant`,`Denomination`,`Adresse`,`Localite`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?);)";
        	        Date date = new Date(0);
        			java.sql.PreparedStatement S = C.prepareStatement(query);
        			S.setInt(1, Integer.parseInt(TxtDoss.getText()));
        			S.setString(2,TxtNom.getText());
        			S.setString(3, TxtPrenom.getText());
        			S.setString(4, TxtNom1.getText());
        			S.setString(5, TxtPrenom1.getText());
        			S.setInt(6, Integer.parseInt(TxtCIN1.getText()));
        			S.setInt(7, Integer.parseInt(TxtCIN2.getText()));
        			S.setDate(8, date.valueOf("+TxtDate1.getText()+"));
        			S.setDate(9, date.valueOf("+TxtDate2.getText()+"));
        			S.setString(10, TxtDenom.getText());
        			S.setString(11, TxtAdresse.getText());
        		    S.setString(12, (String) ville.getSelectedItem());
        			S.executeUpdate();
     
    	            JOptionPane.showMessageDialog(null,"Inscription ajoutée ");
     
     
      } catch(Exception e){
    	    e.printStackTrace() ;
           JOptionPane.showMessageDialog(null," Erreur de la nouvelle inscription \n"+e.getMessage()); 
      }
    }
    private void BtnsuivantActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuivActionPerformed
    try{
    	vehicule Fenetre = new vehicule();
    }catch(Exception e){
        JOptionPane.showMessageDialog(null,"Erreur !! \n"+e.getMessage()); 
     }
     
    }
    public static void main(String args[])// méthode main
    {
     Inscription Fenetre = new Inscription();
    }
    }

  15. #15
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Donne nous la stacktrace de l'erreur. Là tout ce qu'on peut te dire avec ce que tu nous fournis comme informations parcelaire, c'est que t'as un problème quelque part entre le try et le catch, comment tu veux qu'on t'aide si tu ne fournis pas l'information qu'on te demande. Tu met un e.printStackTrace() dans tes catch et tu nous dis ce qui apparait dans la console

  16. #16
    Membre averti
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    230
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 230
    Points : 310
    Points
    310
    Par défaut
    Citation Envoyé par RimyAD Voir le message
    On m'écrit : erreur for input string "" je dois rendre mon travaille la semaine prochaine ! et je bloque sur cette partie !!
    RimyAD, voici un exemple de stacktrace :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    java.lang.NullPointerException
        at Maze.getNumRandOccupants(Maze.java:118)
        at P4TestDriver.testMaze(P4TestDriver.java:995)
        at P4TestDriver.main(P4TestDriver.java:116)
        at __SHELL8.run(__SHELL8.java:7)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at bluej.runtime.ExecServer$3.run(ExecServer.java:814)
    C'est de cela dont nous avons besoin pour t'aider à avancer, on ne peut rien faire sans donc copie-colle nous la stacktrace de ton erreur, ne nous dis pas "on m'écrit que", tu ouvres ta consoles et tu recopies le contenu.

  17. #17
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    Ah Ok ! Je suis désolée voilà ce qu'on m'afficher:

    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
    java.lang.NumberFormatException: For input string: ""
    	at java.lang.NumberFormatException.forInputString(Unknown Source)
    	at java.lang.Integer.parseInt(Unknown Source)
    	at java.lang.Integer.parseInt(Unknown Source)
    	at Inscription.BtnenregistrerActionPerformed(Inscription.java:297)
    	at Inscription.access$1(Inscription.java:284)
    	at Inscription$2.actionPerformed(Inscription.java:260)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$200(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

  18. #18
    Membre expérimenté Avatar de Nico02
    Homme Profil pro
    Developpeur Java/JEE
    Inscrit en
    Février 2011
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Developpeur Java/JEE
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2011
    Messages : 728
    Points : 1 622
    Points
    1 622
    Par défaut
    Le message est pourtant assez explicite je trouve.

    java.lang.NumberFormatException: For input string: ""
    Tu essais de formater une chaîne vide. Comme il n'y a pas de représentation en entier pour une chaîne vide, il est pas très content. Regarde ici


    Dans ces 3 lignes tu dois probablement avoir un getText() qui te renvoi une chaîne vide.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    java.sql.PreparedStatement S = C.prepareStatement(query);
    S.setInt(1, Integer.parseInt(TxtDoss.getText()));
    S.setInt(6, Integer.parseInt(TxtCIN1.getText()));
    S.setInt(7, Integer.parseInt(TxtCIN2.getText()));
    A toi de vérifier avant si toute tes données sont bonnes avant de les insérer dans ta requête.

  19. #19
    Membre averti Avatar de toutgrego
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mai 2013
    Messages
    217
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2013
    Messages : 217
    Points : 350
    Points
    350
    Par défaut
    Moi je pense que ce sont ces lignes là qui posent problème aussi:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    S.setDate(8, date.valueOf("+TxtDate1.getText()+"));
     S.setDate(9, date.valueOf("+TxtDate2.getText()+"));

    =)
    F*ck it ! Do it !

  20. #20
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    Que dois je faire les amis ?? Aidez moi

Discussions similaires

  1. Problème lors de l'insertion de données
    Par galoi81 dans le forum Oracle
    Réponses: 14
    Dernier message: 30/07/2007, 17h10
  2. [PDO] Problème lors d'un INSERT ou un DELETE
    Par WerKa dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 11/06/2007, 16h19
  3. [VB 2005][SQL SERVER]Problème lors de l'insert
    Par LauBelette dans le forum Accès aux données
    Réponses: 4
    Dernier message: 26/12/2006, 04h59
  4. Réponses: 3
    Dernier message: 26/04/2006, 09h16
  5. [JDesktopPane] Problème lors de l'insertion d'une JInternalFrame
    Par Invité dans le forum Agents de placement/Fenêtres
    Réponses: 5
    Dernier message: 21/09/2005, 02h38

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