Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

private void btnupdateActionPerformed(java.awt.event.

ActionEvent evt) {

// TODO add your handling code here:

if(txtid.getText().isEmpty()){

alert("please enter student ID");

return;

if(txtfname.getText().isEmpty()){

alert("please enter firstname");

return;

if(txtlname.getText().isEmpty()){

alert("please enter last name");

return;

if(combogender.getSelectedItem()== null){

alert("please enter gender");

return;

if(combocourse.getSelectedItem()== null){

alert("please enter course");

return;

if(comboyear.getSelectedItem()== null){

alert("please enter year");

return;

if(combosem.getSelectedItem()== null){

alert("please enter semester");

return;
}

if(txtdate.getText().isEmpty()){

alert("please enter Date of Birth");

return;

DefaultTableModel model = (DefaultTableModel) studenttable.getModel();

Student std = new


Student(txtid.getText(),txtfname.getText(),txtlname.getText(),combogender.getSelectedItem().toString(),
combocourse.getSelectedItem().toString(),Integer.parseInt(comboyear.getSelectedItem().toString()),Inte
ger.parseInt(combosem.getSelectedItem().toString()),txtdate.getText());

try {

String sql = "UPDATE STUDENT SET FIRSTNAME=?,LASTNAME


=?,GENDER=?,COURSE=?,YEAR=?,SEMESTER=?,DOB=? WHERE STUDENTID = ?";

pstmt = conn.prepareStatement(sql);

pstmt.setString(1, std.getFirstname());

pstmt.setString(2, std.getLastname());

pstmt.setString(3, std.getGender());

pstmt.setString(4, std.getCourse());

pstmt.setInt(5, std.getYear());

pstmt.setInt(6, std.getSem());

pstmt.setString(7, std.getDOB());

pstmt.setString(8, std.getStdid());

pstmt.executeUpdate();

alert("Update was successful");


model.setRowCount(0);

fetch();

} catch (SQLException ex) {

Logger.getLogger(DatabaseOps.class.getName()).log(Level.SEVERE, null, ex);

Student std = new


Student(txtid.getText(),txtfname.getText(),txtlname.getText(),combogender.getSelectedItem().toString(),
combocourse.getSelectedItem().toString(),Integer.parseInt(comboyear.getSelectedItem().toString()),Inte
ger.parseInt(combosem.getSelectedItem().toString()),txtdate.getText());

DefaultTableModel model1 = (DefaultTableModel) studenttable.getModel();

try{

String SQL = "DELETE FROM STUDENT WHERE STUDENTID = ?";

pstmt = conn.prepareStatement(SQL);

pstmt.setString(1, std.getStdid());

pstmt.executeUpdate();

alert("RECORD DELETED");

model1.setRowCount(0);

fetch();

}catch(SQLException e){

Logger.getLogger(registrationform.class.getName()).log(Level.SEVERE, null, e);

You might also like