0

Actually I'm developing an attendance Software and for this I'm using NetBeans IDE 8.2. I want to pass data from one frame to another and then insert all together in MYSQL. These are the pictures of Both frames through which I want data to pass and save it to MYSQL.

I want after entering all the required data by the user and when user clicks to next button. FinalRegister frame should appear and for that this is what i had done behind next button

  private void    jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    FinalRegister fr = new FinalRegister();
    fr.setVisible(true);  
  }

Now, After this I want after entering all the required data by the user and when user clicks to register button all the data of Previous frame(Register) and this Frame(finalRegister) should be saved to Mysql and for that I had done this behind register button.

private void jButton_RegisterActionPerformed(java.awt.event.ActionEvent evt) {                                                 
      Register rg = new Register(); 
      String name = Register.jTextField_Name.getText();
      String email = rg.jTextField_Email.getText();
      String contact = rg.jTextField_Contact.getText();
      String clas = (String) rg.jComboBox_Class.getSelectedItem();
      String section = (String) rg.jComboBox_Section.getSelectedItem();
      String subject = (String) rg.jComboBox_SubjectTeacher.getSelectedItem();
      String phstd = (String) rg.jComboBox_Contact.getSelectedItem(); 
      String enrollment = Register.jTextField_EID.getText();
      Date date = new Date(rg.jDateChooser1.getDate().getTime());
      String username = jTextField_Setusername.getText();
      String confirm_username = jTextField_Confirmusername.getText();
      String password = String.valueOf(jPasswordField_Setpassword.getPassword());
      String confirm_password = String.valueOf(jPasswordField_Confirmpassword.getPassword());
      String Security_Question = (String) jComboBox1.getSelectedItem();
      String Security_Answer = String.valueOf(jPasswordField_Securityquestion.getPassword());
      String gender = "Male";
      if(Register.jRadioButton_Others.isSelected()) {
          gender = "Others";
      }
      else
          if(Register.jRadioButton_Female.isSelected()){
              gender = "Female";
          }

      if(verifyfield()){
          PreparedStatement ps;
          String sql = "insert into register values(?,?,?,?,?,?,?,?,?);";

          try {
              ps = javaconnect.getConnection().prepareStatement(sql);
              ps.setString(1,name);
              ps.setString(2,gender);
              ps.setDate(3,date);
              ps.setString(4, clas);
              ps.setString(5, section);
              ps.setString(6, enrollment);
              ps.setString(7, email);
              ps.setString(8, contact); 
              ps.setString(9, subject);
              if(ps.executeUpdate()!=0){
              JOptionPane.showMessageDialog(null, "Registerred Successfully","Information Message",1);
              }
              else{
              JOptionPane.showMessageDialog(null, "Connectivity Error","Error Message",2);
              }
          } catch (SQLException ex) {
              Logger.getLogger(FinalRegister.class.getName()).log(Level.SEVERE, null, ex);
          }
      } 

this is the coding of verifyfield()

  Register rg = new Register();
  String name = Register.jTextField_Name.getText();
  String email = rg.jTextField_Email.getText();
  String contact = rg.jTextField_Contact.getText();
  String clas = (String) rg.jComboBox_Class.getSelectedItem();
  String section = (String) rg.jComboBox_Section.getSelectedItem();
  String subject = (String) rg.jComboBox_SubjectTeacher.getSelectedItem();
  String phstd = (String) rg.jComboBox_Contact.getSelectedItem(); 
  String username = jTextField_Setusername.getText();
  String confirm_username = jTextField_Confirmusername.getText();
  String password = String.valueOf(jPasswordField_Setpassword.getPassword());
  String confirm_password = String.valueOf(jPasswordField_Confirmpassword.getPassword());
  String Security_Question = (String) jComboBox1.getSelectedItem();
  String Security_Answer = String.valueOf(jPasswordField_Securityquestion.getPassword());
  if(name.trim().equals("")||email.trim().equals("")||contact.trim().equals("")||clas.trim().equals("")||section.trim().equals("")||
     subject.trim().equals("")||phstd.trim().equals("")||username.trim().equals("")||confirm_username.trim().equals("")||
     password.trim().equals("")||confirm_password.trim().equals("")||Security_Question.trim().equals("")||Security_Answer.trim().equals("")){
      JOptionPane.showMessageDialog(null, "Some Fields are empty.\nKindly Fill it","Warning",0);
  return false;
  }
  else{
  return true;
  }
}    

Screenshot of 1st Frame

Screenshot of 2nd Frame

Screenshot of Error

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

0 Answers0