bonjours;
mon problem ent j'aimerais bien modifier les colonne d'une table déja enregister dans la
base de donnée mais j'arive pas à réuissir cette tache
voici le code que j'ai fait
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
public class ModifierMater extends JFrame{
JButton b1,b2;
JTextField txtId_matériel,txtdésignation,txtmodel,txtetat,txtLaboratoire,txtNom;
JTextField txtId_matérielm,txtdésignationm,txtmodelm,txtetatm,txtLaboratoirem,txtNomm;
String tId_matérielm,tdésignationm,tmodelm,tetatm,tLaboratoirem,tNomm;
JRadioButton optm,optf;
JTextField tId_matérielM,tdésignationM;
int nb,pos; //pos position actuelle; nb le nombre d'utilisateurs
String tId_matériel,tdésignation,tmodel,tetat,tLaboratoire,tNom;
Border border1;
TitledBorder titledBorder1;
Border border2;
TitledBorder titledBorder2;
// Class Vecteur et User
Vecteur usrs;
User usr;
//Construceur de la class
public ModifierMater(String s,Vecteur us){
super(s);
usrs=new Vecteur(us);
border1 = new EtchedBorder(EtchedBorder.RAISED,Color.yellow,new Color(134, 134, 134));
titledBorder1 = new TitledBorder(border1);
border2 = new EtchedBorder(EtchedBorder.RAISED,Color.yellow,new Color(134, 134, 134));
titledBorder2 = new TitledBorder(border2);
JPanel p=new JPanel(new BorderLayout());
JPanel p2=new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel p3=new JPanel(new GridLayout(8,2));
p3.setBorder(titledBorder1);
p3.setBackground(Color.LIGHT_GRAY);
JPanel p4=new JPanel(new GridLayout(8,2));
p4.setBorder(titledBorder2);
p4.setBackground(Color.LIGHT_GRAY);
JButton b1=new JButton("modifier");
b1.setBackground(Color.LIGHT_GRAY);
p2.add(b1);
JButton b2=new JButton("Annuler");
b2.setBackground(Color.LIGHT_GRAY);
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
dispose();
}
});
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
// connexion a la bd
//chargement du pilote jdbc:odbc
try{
Class.forName("com.mysql.jdbc.Driver");
//Etablissement de la connexion
Connection con = DriverManager.getConnection("jdbc:mysql:///mabase", "root","");
// Création d'une instruction
Statement smt = con.createStatement();
// Exécution d'une requete
String query1 = "SELECT * from materiel order by Id_matériel";
String query2 = "UPDATE materiel SET Id_matériel = [txtId_matérielm],désignation = [txtdésignationm],Model = [txtmodelm],etat = [txtetatm],Laboratoire = [txtLaboratoirem],Nom = [txtNomm]";
ResultSet res= smt.executeQuery(query1);
ResultSet res1= smt.executeQuery(query2);
while(res.next())
{
tId_matériel=res.getString("id_matériel");
tdésignation=res.getString("désignation");
tmodel=res.getString("model");
tetat=res.getString("etat");
tLaboratoire=res.getString("Laboratoire");
tNom=res.getString("Nom");
usr=new User(tId_matériel,tdésignation,tmodel,tetat,tLaboratoire,tNom);
usrs.Add(usr);
}
while(res1.next())
{
tId_matérielm=res1.getString("id_matériel");
tdésignationm=res1.getString("désignation");
tmodelm=res1.getString("model");
tetatm=res1.getString("etat");
tLaboratoirem=res1.getString("Laboratoire");
tNomm=res1.getString("Nom");
usr=new User(tId_matérielm,tdésignationm,tmodelm,tetatm,tLaboratoirem,tNomm);
usrs.Add(usr);
}
con.close();
}
catch(ClassNotFoundException e1) {
System.err.println(" Erreur de chargement du driver :" + e1) ;
}
catch(SQLException sqle) {
System.err.println(" Erreur lors de la connexion : "+ sqle) ;
}
// fermeture bd
}
});
p2.add(b2);
p.add("South",p2);
p3.add(new JLabel("Id_matériel:"));
txtId_matériel=new JTextField();
p3.add(txtId_matériel);
p4.add(new JLabel("Nouveau Id_matériel:"));
txtId_matérielm=new JTextField(10);
p4.add(txtId_matérielm);
p3.add(new JLabel("désignation:"));
txtdésignation=new JTextField();
p3.add(txtdésignation);
p4.add(new JLabel("Nouvelle désignation:"));
txtdésignationm=new JTextField(10);
p4.add(txtdésignationm);
p3.add(new JLabel("model:"));
txtmodel=new JTextField();
p3.add(txtmodel);
p4.add(new JLabel("Nouveau model:"));
txtmodelm=new JTextField(10);
p4.add(txtmodelm);
p3.add(new JLabel("etat:"));
txtetat=new JTextField();
p3.add(txtetat);
p4.add(new JLabel("Nouvelle etat:"));
ButtonGroup g= new ButtonGroup();
optm=new JRadioButton("existe",true);
optf=new JRadioButton("ailleur",false);
g.add(optm);
g.add(optf);
p4.add(optm);
p3.add(new JLabel());
p3.add(new JLabel());
p4.add(new JLabel());
p4.add(optf);
//p3.add(new JLabel());
//p3.add(new JLabel());
p3.add(new JLabel("Nom du Laboratoire:"));
txtLaboratoire=new JTextField();
p3.add(txtLaboratoire);
p4.add(new JLabel("Nouveau Nom du Laboratoire:"));
txtLaboratoirem=new JTextField(10);
p4.add(txtLaboratoirem);
p3.add(new JLabel("Nom de l'employé:"));
txtNom=new JTextField();
p3.add(txtNom);
p4.add(new JLabel("Nouveau Nom de l'employé:"));
txtNomm=new JTextField(10);
p4.add(txtNomm);
p.add(p3,BorderLayout.WEST);
p.add(p4,BorderLayout.EAST);
setContentPane(p);
setSize(500,500);
show();
nb=usrs.v.size();
pos=-1;
if(nb!=0)
{
pos=0;
usr=(User)usrs.v.elementAt(pos);
txtId_matériel.setText(usr.id_matériel);
txtdésignation.setText(usr.désignation);
txtmodel.setText(usr.model);
txtetat.setText(usr.etat);
txtLaboratoire.setText(usr.Laboratoire);
txtNom.setText(usr.Nom);
}
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
dispose();
}
});
this.setSize(400,400);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
/*public static void main(String args[]){
Vecteur us=new Vecteur();
Lister fr=new Lister("Liste des utilisateurs",us);
fr.pack();
fr.show();
} */
}
s'i vous plait répond moi c'urgent
et merci