Bonsoir tout le monde;
je suis entrain de m'appliquer en interface Windows avec java;
veuillez me donner un coup de main; je vous signal que le code compile avec ce message:
run:
BUILD SUCCESSFUL (total time: 1 second)
mais en ajoutant les informations dans la base de donnée rien ne se passe et en bas les ligne rouge
voici la fenêtre que je veux réaliser et pour le moment je suis sur le bouton ajouter :
voici le code de la source:
quand je clic sur run file ça este planter et ces lignes rouges apparaissent:Code:import com.mysql.jdbc.Connection; import com.mysql.jdbc.PreparedStatement; import java.sql.DriverManager; import java.sql.ResultSet; import javax.swing.JOptionPane; import java.sql.*; import javax.swing.table.DefaultTableModel; /** * * @author DAFFE */ public class Menu extends javax.swing.JFrame { Connection con; PreparedStatement pst; ResultSet rs; /** * Creates new form Menu */ public Menu() { initComponents(); connect(); chagerCombobox(); Table(); } public void connect(){ // debut de try try{ Class.forName("com.msql.jdbc.Driver"); con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost/gestionhotel","root",""); JOptionPane.showMessageDialog(null,"Connection reusie"); } catch (Exception e) { e.printStackTrace(); } // fin de try // fin de initialize() } public void Table(){ String [] client={"ID","NOM","TELEPHONE","ADRESSE"}; String [] afficher=new String[5] ; DefaultTableModel model = new DefaultTableModel(null, client); try{ connect(); Statement st=con.createStatement(); rs=st.executeQuery("select * from client"); while(rs.next()){ afficher[0]=rs.getString("id"); afficher[1]=rs.getString("nom"); afficher[2]=rs.getString("tel"); afficher[3]=rs.getString("adresse"); model.addRow(afficher); } jTable1.setModel(model); con.close(); } catch (Exception e){ e.printStackTrace(); } } public void chagerCombobox(){ try{ connect(); Statement st=con.createStatement(); rs=st.executeQuery("select adresse from client"); while(rs.next()){ //Pour affecter une valeur de base de données à un Combobox txtadresse.addItem(rs.getString("adresse")); } con.close(); } catch (Exception e){ e.printStackTrace(); } } /** * 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() { jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel1 = new javax.swing.JPanel(); jPanel3 = new javax.swing.JPanel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); txtadresse = new javax.swing.JComboBox<>(); jButton1 = new javax.swing.JButton(); jLabel5 = new javax.swing.JLabel(); txtid = new javax.swing.JTextField(); txtnom = new javax.swing.JTextField(); txttel = new javax.swing.JTextField(); jButton2 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jPanel2 = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTabbedPane1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); jTabbedPane1.setForeground(new java.awt.Color(51, 51, 255)); jTabbedPane1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jTabbedPane1.setPreferredSize(new java.awt.Dimension(200, 300)); jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try{ connect(); pst=(PreparedStatement)con.prepareStatement("INSERT INTO client(id, nom, tel, adresse)values(?,?,?,?)"); pst.setString(1,txtid.getText()); pst.setString(2,txtnom.getText()); pst.setString(3,txttel.getText()); pst.setString(4,txtadresse.getSelectedItem().toString()); pst.executeUpdate(); con.close(); JOptionPane.showMessageDialog(null, "Client ajouter"); Table(); chagerCombobox(); } catch (Exception e){ e.printStackTrace(); } } private void txtadresseActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void jTable1MouseReleased(java.awt.event.MouseEvent evt) { // TODO add your handling code here: int i=jTable1.getSelectedRow(); DefaultTableModel model=(DefaultTableModel) jTable1.getModel(); txtid.setText(model.getValueAt(i,0).toString()); txtnom.setText(model.getValueAt(i,1).toString()); txttel.setText(model.getValueAt(i,2).toString()); txtadresse.setSelectedItem(model.getValueAt(i,3).toString()); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try{ connect(); pst=(PreparedStatement)con.prepareStatement("UPDATE client SET name=?, tel=?, adresse=? WHERE id=?"); pst.setString(4,txtid.getText()); pst.setString(1,txtnom.getText()); pst.setString(2,txttel.getText()); pst.setString(3,txtadresse.getSelectedItem().toString()); pst.executeUpdate(); con.close(); JOptionPane.showMessageDialog(null, "Client modifier"); Table(); chagerCombobox(); } catch(Exception e){ e.printStackTrace(); } } /** * @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(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Menu.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 Menu().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JTable jTable1; private javax.swing.JComboBox<String> txtadresse; private javax.swing.JTextField txtid; private javax.swing.JTextField txtnom; private javax.swing.JTextField txttel; // End of variables declaration }
compte tenu la longueur du message j'ai supprimé une partie de code d'erreurCode:java.lang.ClassNotFoundException: com.msql.jdbc.Driver at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at Menu.connect(Menu.java:32) at Menu.<init>(Menu.java:26) at Menu$5.run(Menu.java:385) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:726) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
j'ai aussi diminuer le contenu de private void initComponents() {
-----