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

Composants Java Discussion :

ajouter la valeur d'un jTextfield dans ma base


Sujet :

Composants Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Mai 2007
    Messages
    36
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2007
    Messages : 36
    Par défaut ajouter la valeur d'un jTextfield dans ma base
    Bonjour à tous, voici le contexte, j'ai une combo reliée correctement a ma base qui affiche tout les moyens de paiement disponibles, a coté j'ai un jtextfield ou l'utilisateur peu saisir un nouveau mode de paiement et le bouton ajouter permet de l'inserer dans la base, au niveau de la combo pas de probleme les données sont bien importées de la base mais quand je rempli le textfield et que je clique sur ajouter je vois cette erreur la :"connexion impossible: Can not issus data manipulation statements with executeQuery().", et je ne comprend vraiment pas pourquoi la connection est impossible vu que cela marche avec la combo, voici le code de ma page :
    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
    import java.awt.Dimension;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
     
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.SwingConstants;
    public class paiement_famclients {
     
    	private JFrame jFrame_paiement_famclients = null;  //  @jve:decl-index=0:visual-constraint="435,54"
    	private JPanel jContentPane = null;
    	private JPanel jPanel_paiement_famclients = null;
    	private JLabel jLabel_code_paiement_famclients = null;
    	private JLabel jLabel_designation_paiement_famclients = null;
    	private JTextField jTextField_code_paiement_famclients = null;
    	private JTextField jTextField_designation_paiement_famclients = null;
    	private JButton jButton_ajouter_paiement_famclients = null;
    	private JButton jButton_suppr_paiement_famclients = null;
    	private JComboBox jComboBox_mdp_client = null;
    	private JButton jButton_ajouter_famclients = null;
     
    	/**
             * This method initializes jFrame_paiement_famclients   
             *      
             * @return javax.swing.JFrame   
             */
    	public JFrame getJFrame_paiement_famclients() {
    		if (jFrame_paiement_famclients == null) {
    			jFrame_paiement_famclients = new JFrame();
    			jFrame_paiement_famclients.setSize(new Dimension(252, 237));
    			jFrame_paiement_famclients.setTitle("Moyens de paiement");
    			jFrame_paiement_famclients.setLocation(new Point(300, 290));
     
    			jFrame_paiement_famclients.setContentPane(getJContentPane());
    			jFrame_paiement_famclients.setVisible(true);
    		}
    		return jFrame_paiement_famclients;
    	}
     
    	/**
             * This method initializes jContentPane 
             *      
             * @return javax.swing.JPanel   
             */
    	private JPanel getJContentPane() {
    		if (jContentPane == null) {
    			jContentPane = new JPanel();
    			jContentPane.setLayout(null);
    			jContentPane.add(getJPanel_paiement_famclients(), null);
    		}
    		return jContentPane;
    	}
     
    	/**
             * This method initializes jPanel_paiement_famclients   
             *      
             * @return javax.swing.JPanel   
             */
    	private JPanel getJPanel_paiement_famclients() {
    		if (jPanel_paiement_famclients == null) {
    			jLabel_designation_paiement_famclients = new JLabel();
    			jLabel_designation_paiement_famclients.setBounds(new Rectangle(9, 40, 71, 26));
    			jLabel_designation_paiement_famclients.setHorizontalAlignment(SwingConstants.CENTER);
    			jLabel_designation_paiement_famclients.setText("Désignation");
    			jLabel_code_paiement_famclients = new JLabel();
    			jLabel_code_paiement_famclients.setBounds(new Rectangle(9, 10, 71, 26));
    			jLabel_code_paiement_famclients.setHorizontalAlignment(SwingConstants.CENTER);
    			jLabel_code_paiement_famclients.setText("Code");
    			jPanel_paiement_famclients = new JPanel();
    			jPanel_paiement_famclients.setLayout(null);
    			jPanel_paiement_famclients.setBounds(new Rectangle(-1, 0, 245, 201));
    			jPanel_paiement_famclients.add(jLabel_code_paiement_famclients, null);
    			jPanel_paiement_famclients.add(jLabel_designation_paiement_famclients, null);
    			jPanel_paiement_famclients.add(getJTextField_code_paiement_famclients(), null);
    			jPanel_paiement_famclients.add(getJTextField_designation_paiement_famclients(), null);
     
    			jPanel_paiement_famclients.add(getJButton_suppr_paiement_famclients(), null);
    			jPanel_paiement_famclients.add(getJComboBox_mdp_client(), null);
    			jPanel_paiement_famclients.add(getJButton_ajouter_famclients(), null);
    		}
    		{
    			Statement instruction = null;
    			Connection connexion = null;
    			ResultSet resultat = null;
    			try
    			{
    				Class.forName("com.mysql.jdbc.Driver");
     
    				connexion = DriverManager.getConnection("jdbc:mysql://localhost/gescom2","root","");
    				instruction = connexion.createStatement();
     
    				resultat = instruction.executeQuery("SELECT lib_mdp FROM mode_de_paiement" );
     
     
    				while(resultat.next())
    				{
    					jComboBox_mdp_client.addItem((resultat.getString("lib_mdp")));
    				}
     
     
     
     
     
     
     
    			}
    			catch (ClassNotFoundException ex)
    			{
    				JOptionPane.showMessageDialog(null,"Classe introuvable" + ex.getMessage());
    			}
    			catch (SQLException ex)
    			{
    				JOptionPane.showMessageDialog(null, "Connexion impossible:" +ex.getMessage());
    			}
    			finally
    			{
    				try
    				{
     
    					if(connexion !=null)
    						connexion.close();
    					if(instruction !=null)
    						instruction.close();
    					if (connexion !=null)
    						connexion.close();
    				}
    				catch (SQLException ex)
    				{
    					ex.printStackTrace();
    				}
    			}
    	}
     
    		return jPanel_paiement_famclients;
    	}
     
    	/**
             * This method initializes jTextField_code_paiement_famclients  
             *      
             * @return javax.swing.JTextField       
             */
    	private JTextField getJTextField_code_paiement_famclients() {
    		if (jTextField_code_paiement_famclients == null) {
    			jTextField_code_paiement_famclients = new JTextField();
    			jTextField_code_paiement_famclients.setBounds(new Rectangle(89, 11, 153, 24));
    			jTextField_code_paiement_famclients.getText();
     
    		}
    		return jTextField_code_paiement_famclients;
    	}
     
    	/**
             * This method initializes jTextField_designation_paiement_famclients   
             *      
             * @return javax.swing.JTextField       
             */
    	private JTextField getJTextField_designation_paiement_famclients() {
    		if (jTextField_designation_paiement_famclients == null) {
    			jTextField_designation_paiement_famclients = new JTextField();
    			jTextField_designation_paiement_famclients.setBounds(new Rectangle(89, 41, 153, 24));
    			jTextField_designation_paiement_famclients.getText();
    		}
    		return jTextField_designation_paiement_famclients;
    	}
     
    	/**
             * This method initializes jButton_ajouter_paiement_famclients  
             *      
             * @return javax.swing.JButton  
             */
     
    	/**
             * This method initializes jButton_suppr_paiement_famclients    
             *      
             * @return javax.swing.JButton  
             */
    	private JButton getJButton_suppr_paiement_famclients() {
    		if (jButton_suppr_paiement_famclients == null) {
    			jButton_suppr_paiement_famclients = new JButton();
    			jButton_suppr_paiement_famclients.setBounds(new Rectangle(148, 109, 94, 21));
    			jButton_suppr_paiement_famclients.setText("Supprimer");
    		}
    		return jButton_suppr_paiement_famclients;
    	}
     
    	/**
             * This method initializes jComboBox_mdp_client 
             *      
             * @return javax.swing.JComboBox        
             */
    	private JComboBox getJComboBox_mdp_client() {
    		if (jComboBox_mdp_client == null) {
    			jComboBox_mdp_client = new JComboBox();
    			jComboBox_mdp_client.setBounds(new Rectangle(14, 80, 123, 23));
    			jComboBox_mdp_client.setEditable(true);
    		}
    		return jComboBox_mdp_client;
    	}
     
    	/**
             * This method initializes jButton_ajouter_famclients   
             *      
             * @return javax.swing.JButton  
             */
    	private JButton getJButton_ajouter_famclients() {
    		if (jButton_ajouter_famclients == null) {
    			jButton_ajouter_famclients = new JButton();
    			jButton_ajouter_famclients.setBounds(new Rectangle(148, 80, 92, 24));
    			jButton_ajouter_famclients.setText("Ajouter");
    			jButton_ajouter_famclients.addActionListener(new java.awt.event.ActionListener() {
    			public void actionPerformed(java.awt.event.ActionEvent e){
    			{
    				Statement instruction = null;
    				Connection connexion = null;
    				ResultSet resultat = null;
    				try
    				{
    					Class.forName("com.mysql.jdbc.Driver");
     
    					connexion = DriverManager.getConnection("jdbc:mysql://localhost/gescom2","root","");
    					instruction = connexion.createStatement();
     
    					resultat = instruction.executeQuery("INSERT INTO mode_de_paiement (code_mdp) VALUES"+jTextField_code_paiement_famclients.getText());
     
     
     
     
     
    				}
    				catch (ClassNotFoundException ex)
    				{
    					JOptionPane.showMessageDialog(null,"Classe introuvable" + ex.getMessage());
    				}
    				catch (SQLException ex)
    				{
    					JOptionPane.showMessageDialog(null, "Connexion impossible:" +ex.getMessage());
    				}
    				finally
    				{
    					try
    					{
     
    						if(connexion !=null)
    							connexion.close();
    						if(instruction !=null)
    							instruction.close();
    						if (connexion !=null)
    							connexion.close();
    					}
    					catch (SQLException ex)
    					{
    						ex.printStackTrace();
    					}
    				}
    		}
    			}
    			});
    		}
     
     
    		return jButton_ajouter_famclients;
    	}
     
    }
    merci d'avance pour vos réponses

  2. #2
    Membre Expert
    Avatar de afrikha
    Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    1 600
    Détails du profil
    Informations personnelles :
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2005
    Messages : 1 600
    Par défaut
    Salut,

    Essaye de remplacer executeQuery par execute ou bien executeUpdate

    @+


    Mes publications
    Lisez
    Les régles du forum
    Pensez au bouton

  3. #3
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Mai 2007
    Messages
    36
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2007
    Messages : 36
    Par défaut
    si je met execute jbuilder me dit :
    Non condordance des types : impossible de convertir Boolean en ResultSet
    si je met executeUpdate il m'affiche :
    Non condordance des types : impossible de convertir int en ResultSet

  4. #4
    Membre Expert
    Avatar de afrikha
    Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    1 600
    Détails du profil
    Informations personnelles :
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2005
    Messages : 1 600
    Par défaut
    Ben c'est normal vu que execute renvoie un Boolean et executeUpdate renvoie un int...donc tu peux pas affecter le resultat à un type ResultSet.

    Remplace la ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    resultat = instruction.executeQuery("INSERT INTO mode_de_paiement (code_mdp) VALUES"+jTextField_code_paiement_famclients.getText());
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Boolean resultat2 = instruction.execute("INSERT INTO mode_de_paiement (code_mdp) VALUES"+jTextField_code_paiement_famclients.getText());
    @+


    Mes publications
    Lisez
    Les régles du forum
    Pensez au bouton

  5. #5
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Mai 2007
    Messages
    36
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2007
    Messages : 36
    Par défaut
    cela m'affiche l'erreur :
    Connexion impossible : Erreur de syntaxe près de 'VALUES145' à la ligne 1
    et pareil avec int et executeUpdate

  6. #6
    Membre Expert
    Avatar de afrikha
    Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    1 600
    Détails du profil
    Informations personnelles :
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2005
    Messages : 1 600
    Par défaut
    Tu n'aurais oublié des parenthèses par hazard...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Boolean resultat2 = instruction.execute("INSERT INTO mode_de_paiement (code_mdp) VALUES("+jTextField_code_paiement_famclients.getText()+")");
    Merci de faire un minimum d'effort et de faire des recherches...


    Mes publications
    Lisez
    Les régles du forum
    Pensez au bouton

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Ajouter une valeur d'un JTextField dans la liste des menuitems
    Par moniayousfi dans le forum AWT/Swing
    Réponses: 7
    Dernier message: 30/04/2015, 15h47
  2. [Débutant] Ajouter des valeurs à une liste situé dans une classe
    Par MPothin dans le forum Windows Forms
    Réponses: 1
    Dernier message: 27/08/2014, 15h05
  3. ajouter une valeur d'une clé dans une map
    Par chirazch dans le forum C++
    Réponses: 7
    Dernier message: 06/05/2013, 18h36
  4. Récuperer valeurs d'une checkbox dans la base Mysql
    Par pod1978 dans le forum SQL Procédural
    Réponses: 13
    Dernier message: 10/03/2006, 14h29
  5. Ajouter un champs de type " Date " dans ma base ac
    Par hysteresis dans le forum Langage SQL
    Réponses: 16
    Dernier message: 10/10/2005, 16h10

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