private void isEdit(Boolean isEdit) { if (isEdit) { try { Connection con = FrameLogin.getConnect(); String sql = "SELECT * FROM Persons WHERE personId = " + Id; Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql); if (rs.first()) { String firstname = rs.getString("FirstName"); String lastname = rs.getString("LastName"); String cellphone = rs.getString("CellPhoneNo"); String homephone = rs.getString("HomePhoneNo"); String gradyear = rs.getString("Graduation Year"); String Gender = rs.getString("Gender"); firstName.setText(firstname); lastName.setText(lastname); cellPhone.setText(cellphone); homePhone.setText(homephone); gradYear.setText(gradyear); gender.setSelectedItem(Gender); jLabel7.setVisible(false); studentId.setVisible(false); } else { MessageBox.infoBox("Error: ID not found", "Error"); } } catch (Exception e) { MessageBox.infoBox(e.toString(), "Error in isEdit"); } } FrameLogin.closeConnect(); }
private void submitButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_submitButtonActionPerformed // TODO add your handling code here: Connection con = FrameLogin.getConnect(); String SQLInsert = "INSERT INTO `2761DB`.`Persons` (`FirstName`, `LastName`, `CellPhoneNo`, `HomePhoneNo`, " + "`SchoolId`, `Graduation Year`, `Gender`) VALUES ('" + firstName.getText() + "', '" + lastName.getText() + "', '" + cellPhone.getText() + "', '" + homePhone.getText() + "', '" + studentId.getText() + "', '" + gradYear.getText() + "', '" + (String) (gender.getSelectedItem()) + "');"; String SQLUpdate = "UPDATE `2761DB`.`Persons` SET `FirstName` = '" + firstName.getText() + "', `LastName` = '" + lastName.getText() + "', `CellPhoneNo` = ' " + cellPhone.getText() + "', `HomePhoneNo` = '" + homePhone.getText() + "', `Graduation Year` = '" + gradYear.getText() + "', `Gender` = '" + (String) (gender.getSelectedItem()) + "' WHERE `PersonId` = '" + Id + "';"; // UPDATE `2761DB`.`Persons` SET `FirstName`='Robbie', `LastName`='Tacescu', `CellPhoneNo`='', // `HomePhoneNo`='559300', `SchoolId`='15648916', `Graduation Year`='6545', `Gender`='males' // WHERE // `PersonId`='42'; try { if (isEdit) { Statement stmt = con.createStatement(); // System.out.println(SQLUpdate); stmt.executeUpdate(SQLUpdate); } else { Statement stmt = con.createStatement(); // System.out.println(SQLInsert); stmt.executeUpdate(SQLInsert); } } catch (SQLException err) { MessageBox.infoBox(err.toString(), "Error in AddUserForm submitButton"); } FrameLogin.closeConnect(); this.dispose(); } // GEN-LAST:event_submitButtonActionPerformed