Update Data using MySQL Database and Java with Netbeans IDE

0
116

This tutorial entitled Update Data using MySQL Database and Java with Netbeans IDE will teach you on how to update a data stored in MySQL Database using Java and Netbens IDE.

Before we start, be sure that you already follow and learned my last tutorial on how to Load Data into another form.

Update Data using MySQL Database and Java with Netbeans IDE Steps

  1. In my last tutorial entitled Display Data from Selected Table Row to another Form in JavaWe already created a new JFrame Form for our update function. The form should look like the image below.

2. Double click the button “UPDATE” and insert the following codes below.

  1. try{
  2. String fname = jLabel1.getText();
  3. String lname = jLabel2.getText();
  4. String address = jLabel3.getText();
  5. String contact = jLabel4.getText();
  6. String email = jLabel5.getText();
  7. String str="UPDATE userinfo SET "
  8. + "FirstName='" + fname + "',LastName='" + lname + "',Address='" + address + "',Contact='" + contact + "',Email='" + email + "'"
  9. + "WHERE idUserInfo='" + idn + "'";
  10. pst=conn.prepareStatement(str);
  11. pst.execute();
  12. JOptionPane.showMessageDialog(null,"Data Successfully Updated!");
  13. clear_fields();
  14. }catch (HeadlessException | SQLException e){
  15. JOptionPane.showMessageDialog(this, e.getMessage());
  16. }

3. Run your program and the output should look like the image below. When I click the update button, a dialog box appear saying “Data Successfully Updated!”. It means that the update function is successfully executed.

Related Articles You May Like:

Facebook Comments
(Visited 124 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here