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

AWT/Swing Java Discussion :

Recuperer du "texte" dans un jTexfield


Sujet :

AWT/Swing 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 Recuperer du "texte" dans un jTexfield
    Bonjour a Tous, j'ai créé une requete qui permet de recuperer les informations de 2 Texfield et de les inserer dans ma base de données, probleme, si je met autre chose que des chiffres une erreur s'affiche quand je clique sur mon bouton ajouter du type : connexion impossible : champ 'blabla' inconnu dans field list; voici 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
    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
    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();
    					if ((jTextField_code_paiement_famclients.getText() != " ") && (jTextField_designation_paiement_famclients.getText() != " "))
    					{
     
     
    						instruction.executeUpdate("INSERT INTO mode_de_paiement(code_mdp,lib_mdp) VALUES("+jTextField_code_paiement_famclients.getText()+","+jTextField_designation_paiement_famclients.getText()+")");
     
    					}
     
    					else {
    						JOptionPane.showMessageDialog(null,"Attention, veuillez remplir le code ET la désignation");
    						}
     
     
     
     
     
     
    				}
    				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;
    	}
     
    }

  2. #2
    Membre éprouvé
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 83
    Par défaut
    C'est normal, tu as écris

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    instruction.executeUpdate("INSERT INTO mode_de_paiement(code_mdp,lib_mdp) VALUES("+jTextField_code_paiement_famclients.getText()+","+jTextField_designation_paiement_famclients.getText()+")");
    mais en sql quand tu dois faire un insert avec des string tu dois utiliser 'monString'.

    autrement dis:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    instruction.executeUpdate("INSERT INTO mode_de_paiement(code_mdp,lib_mdp) VALUES('"+jTextField_code_paiement_famclients.getText()+"','"+jTextField_designation_paiement_famclients.getText()+"')");
    Pour être plus lisible :

    ' "+jTextField_code_paiement_famclients.getText()+" '

  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
    merci beaucoup pour cette réponse, je n'avait pas fais attention a ca, cela marche parfaitement

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

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