Bonjour, Excusez moi, je vous présente mon code en java, il affiche après complilation il affiche toujours erreur de connexion
voici le code
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Creates new form FormStagiaire
*/
public FormStagiaire() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
txtNumero = new javax.swing.JTextField();
txtNom = new javax.swing.JTextField();
txtSexe = new javax.swing.JTextField();
txtDateNaiss = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
TableStag = new javax.swing.JTable();
btnFirst = new javax.swing.JButton();
btnPrev = new javax.swing.JButton();
btnNext = new javax.swing.JButton();
btnLast = new javax.swing.JButton();
btnRechercher = new javax.swing.JButton();
btnAfficher = new javax.swing.JButton();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jLabel5 = new javax.swing.JLabel();
txtRechercher = new javax.swing.JTextField();
btnAjouter = new javax.swing.JButton();
btnModifier = new javax.swing.JButton();
btnSupprimer = new javax.swing.JButton();
private void txtNomActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
try{
//Connexion avec une base de donnée
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cnx = DriverManager.getConnection("jdbc:odbc:Gestion de stagiaire");
St = cnx.createStatement();
}catch(Exception e){
JOptionPane.showMessageDialog(null,"Error connection\n" +e.getMessage());
}
} <gras>
//Procedure pour afficher la liste des stagiaire private void AfficherStagiaire(){
try{
dt.setRowCount(0);//vider la liste des stagiaires
Rs = St.executeQuery("Select * From Stag");
while(Rs.next()){
Numero = Rs.getInt("Numero");
Nom = Rs.getString("Nom");
Sexe = Rs.getString("Sexe");
dateNaiss = Rs.getDate("dateNaiss");
Object[] Stag = {Numero,Nom,Sexe,dateNaiss};
dt.addRow(Stag);
}
}catch(Exception e){
JOptionPane.showMessageDialog(null,"Erreur afficher la liste des stagiaire\n" +e.getMessage());</gras>
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FormStagiaire.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FormStagiaire.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FormStagiaire.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FormStagiaire.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FormStagiaire().setVisible(true);
}
});
}
// Declaration de variable
private Connection cnx;
private Statement St;
private ResultSet Rs;
private DefaultTableModel dt;
private Date dateNaiss;
private int Numero;
private String Nom,Sexe;
private int j;//indice de déplacement