Se connecter avec
S'enregistrer | Connectez-vous

erreur java

Dernière réponse : dans Programmation

salutations à tous!!

j'ai une erreur dont je ne connais pas la cause
lorsque je souhaite inserer un client dans une table MSQL client (num_client, nom, adresse, cp, ville, tel, nbre_plan)
mais un probleme surgi
voici mon code :

  1. package com.inserer.test;
  2.  
  3.  
  4.  
  5. import java.awt.event.*;
  6. import java.sql.*;
  7. import java.awt.*;
  8. import javax.swing.JPanel;
  9. import javax.swing.JOptionPane;
  10. import javax.swing.*;
  11.  
  12.  
  13.  
  14.  
  15. public class Inserer extends Frame implements ActionListener
  16. {
  17.  
  18.  
  19.  
  20. Frame f = new Frame("exercice");
  21. TextField num = new TextField("Numero du client", 20);
  22. TextField nom = new TextField("Nom du client", 20);
  23. TextField adresse = new TextField("Adresse", 20);
  24. TextField cp = new TextField("Code postal", 20);
  25. TextField ville = new TextField("Ville", 20);
  26. TextField tel = new TextField("Telephone", 20);
  27. TextField plan = new TextField("Nombre de plan", 20);
  28.  
  29. Label message = new Label();
  30. Button quitter = new Button("QUITTER L'APPLICATION");
  31. Button inserer = new Button("INSERER ");
  32. Panel panneau = new Panel();
  33.  
  34.  
  35.  
  36. public Inserer() {
  37.  
  38. num.addActionListener(this);
  39. nom.addActionListener(this);
  40. adresse.addActionListener(this);
  41. cp.addActionListener(this);
  42. ville.addActionListener(this);
  43. tel.addActionListener(this);
  44. plan.addActionListener(this);
  45. inserer.addActionListener(this);
  46.  
  47. num.selectAll(); // pour sélectionner le texte du champ
  48. nom.selectAll();
  49. adresse.selectAll();
  50. cp.selectAll();
  51. ville.selectAll();
  52. tel.selectAll();
  53. plan.selectAll();
  54.  
  55. setLayout(new FlowLayout());
  56. add(num);
  57. add(nom);
  58. add(adresse);
  59. add(cp);
  60. add(ville);
  61. add(tel);
  62. add(plan);
  63. add(quitter);
  64. add(inserer);
  65.  
  66. setBounds(40, 60, 300, 200);
  67. setTitle("INSERER UN NOUVEAU CLIENT");
  68. setSize(300, 350);
  69. setVisible(true);
  70.  
  71. }
  72.  
  73. public void actionPerformed(ActionEvent e) {
  74. if (e.getSource()== inserer)
  75. //if (e.getSource() == num)
  76. //if (e.getSource() == nom)
  77. //if (e.getSource() == adresse)
  78. //if (e.getSource() == cp)
  79. //if (e.getSource() == ville)
  80. //if (e.getSource() == tel)
  81. //if (e.getSource() == plan)
  82.  
  83. {
  84.  
  85. Connection con = null;
  86. Statement instruction = null;
  87. ResultSet resultat = null;
  88.  
  89. try {
  90. Class.forName("com.mysql.jdbc.Driver");
  91. con = DriverManager.getConnection(
  92. "jdbc:mysql://localhost/techniclim",
  93. "root", "");
  94. instruction = con.createStatement();
  95.  
  96. int res = instruction.executeUpdate
  97. ("INSERT INTO client(num_client, nom, adresse, cp, ville, tel, nbre_plan) VALUES ( " +
  98. num.getText() + ", " + nom.getText() +
  99. " , " + adresse.getText() +
  100. " , " + cp.getText() +
  101. " , " + ville.getText() +
  102. " , " + tel.getText() +
  103. " , " + plan.getText() + " )");
  104.  
  105.  
  106.  
  107.  
  108. JOptionPane.showMessageDialog(null,
  109. "Client :" + nom.getText() + " ajouté avec succès");
  110. //"\u20ac");
  111.  
  112.  
  113. } catch (ClassNotFoundException ex) {
  114. JOptionPane.showMessageDialog(null,
  115. "Classe introuvable" +
  116. ex.getMessage());
  117. } catch (SQLException ex) {
  118. JOptionPane.showMessageDialog(null,
  119. "erreur JDBC : " +
  120. ex.getMessage());
  121. } finally {
  122. try
  123.  
  124. {
  125.  
  126. if (resultat != null)
  127. resultat.close();
  128. if (con != null)
  129. con.close();
  130. } catch (SQLException ex) {
  131. ex.printStackTrace();
  132. System.exit(0);
  133. }
  134. }
  135. }
  136. }
  137. public static void main(String[] arg) {
  138. Frame f = new Inserer();
  139. }
  140. }



erreur :
erreur JDBC : Erreur de syntaxe près de 'du client, adresse, code postal, ville, telephone, no'

mais j'ai beau cherché je ne vois pas du tout où est ce que j'ai pu faire une erreur

thanks!!















Autres pages sur : erreur java

Lassé par la pub ? Créez un compte
Expert Programmation

Oula, tu as un problème récurrent avec le SQL.
Et les quotes autour des strings ?
  1. "INSERT INTO client (num_client, nom, adresse, cp, ville, tel, nbre_plan ) " +
  2. "VALUES ( " + num.getText() + ", '" + nom.getText() + "', '" + adresse.getText() + "', '" +
  3. cp.getText() + "', '" + ville.getText() + "', '" + tel.getText() + "', " +
  4. plan.getText() + " )" );

Là, c'est mieux.
Lassé par la pub ? Créez un compte