Probleme d'insertion d'elements dans ma base de données

edgardjok Messages postés 12 Date d'inscription samedi 10 novembre 2001 Statut Membre Dernière intervention 17 août 2009 - 3 août 2009 à 17:29
edgardjok Messages postés 12 Date d'inscription samedi 10 novembre 2001 Statut Membre Dernière intervention 17 août 2009 - 3 août 2009 à 18:14
Bonjour je viens d'ecrire une classe véhicule qui se connecte parfaitement à ma base de données mais le probleme est que j'ai pas l'insertion dans ma base de données. voici le code source et l'erreur que j'ai.

package traitement;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.GridLayout;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.ButtonGroup;
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.JRadioButton;

public class VehiculeIHM extends JPanel{

private JComboBox nameBox, optionBox, typeBox, carburantBox, typeMarqBox;
private JButton okButton;
private JRadioButton pretRadio, cashRadio;
private String nomVeh,nomType,nomOpt,nomMarq,nomCab;
Connection cx = null;
Statement stmt;

private static String url ="jdbc:mysql://localhost/db_gestion_veh";


public VehiculeIHM(){
String []tabVeh = {"Mercedes", "BMW", "Peugeot", "Nissan","Jaguar","Maserati","Audi"};
String []tabType = {"4*4", "Berline", "Cabriolet"};
String []tabOpt = {"Manuel","Automatique"};
String []tabMarqVeh ={"CLS","330TDI","607","Frontiera","XJR","Spyder","TTS"};
String []tabCab = {"Essence","Diesel"};

nameBox = new JComboBox(tabVeh);
JLabel nameLabel = new JLabel("Nom du vehicule");
nameLabel.setLabelFor(nameBox);
add(nameLabel);
add(nameBox);
typeBox = new JComboBox(tabType);
JLabel typeLabel = new JLabel("Type");
typeLabel.setLabelFor(typeBox);
add(typeLabel);
add(typeBox);
optionBox = new JComboBox(tabOpt);
JLabel opLabel = new JLabel("Option");
opLabel.setLabelFor(optionBox);
add(opLabel);
add(optionBox);
typeMarqBox = new JComboBox(tabMarqVeh);
JLabel typeMarqLabel = new JLabel("Type de marque");
typeMarqLabel.setLabelFor(typeMarqBox);
add(typeMarqLabel);
add(typeMarqBox);
carburantBox = new JComboBox(tabCab);
JLabel carburantLabel = new JLabel("Carburant");
carburantLabel.setLabelFor(carburantBox);
add(carburantLabel);
add(carburantBox);


pretRadio = new JRadioButton("PRET",true);
cashRadio = new JRadioButton("CASH");
ButtonGroup group = new ButtonGroup();
group.add(pretRadio);
group.add(cashRadio);
add(pretRadio);
add(cashRadio);

okButton = new JButton("Soumettre");
add(okButton, BorderLayout.SOUTH);
GridLayout gl = new GridLayout(7,0);
setLayout(gl);
okButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
//tre traitement.
nomVeh = nameBox.getSelectedItem().toString();
nomType = typeBox.getSelectedItem().toString();
nomOpt = optionBox.getSelectedItem().toString();
nomMarq = typeMarqBox.getSelectedItem().toString();
nomCab = carburantBox.getSelectedItem().toString();
try{

Class.forName("com.mysql.jdbc.Driver").newInstance();

cx = DriverManager.getConnection(url,"root","");
Statement stmt = cx.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

String requete = "insert into tableclient values('"+nomVeh+
"','"+nomType+
"','"+nomOpt+
"','"+nomMarq+
"','"+nomCab+"')";
System.out.println(requete);
stmt.executeUpdate(requete);



JOptionPane.showMessageDialog(new JFrame(),"Opération terminée avec succès"
,"Confirmation",JOptionPane.OK_CANCEL_OPTION);
cx.close();

}catch (Exception e) {

e.printStackTrace();

}

if(pretRadio.isSelected()){
new Emprunt();
}
}

});
}
}


insert into tableclient values('Mercedes','4*4','Manuel','CLS','Essence')
java.sql.SQLException: Column count doesn't match value count at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1605)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1524)
at traitement.VehiculeIHM$1.actionPerformed(VehiculeIHM.java:100)

2 réponses

kirua12 Messages postés 1155 Date d'inscription samedi 17 janvier 2004 Statut Membre Dernière intervention 29 avril 2011 7
3 août 2009 à 18:02
Salut,

il serait bon d'apprendre à lire les erreurs : nombre de colonnes ne correspond pas. Tu as 5 valeurs dans ton insert mais ta table en a moins de 5 ou plus de 5.
Vérifie ton insert ou la structure de ta table.
0
edgardjok Messages postés 12 Date d'inscription samedi 10 novembre 2001 Statut Membre Dernière intervention 17 août 2009
3 août 2009 à 18:14
sorry resolu
hello world!
0
Rejoignez-nous