I am following along with this tutorial which has been really helpful so far. I am making a GUI to perform CRUD operations on a locally hosted Java derby database.
Here's my problem:
How do I make my JTextFields update to reflect the new data without having to close and rerun the program?
private void btnUpdateRecordActionPerformed(java.awt.event.ActionEvent evt) {
String customerID = textCustomerID.getText();
int newCustomerID = Integer.parseInt(customerID);
String name = textName.getText();
String address1 = textAddress1.getText();
String address2 = textAddress2.getText();
String phone = textPhone.getText();
String email = textEmail.getText();
try{
rs.updateInt("CUSTOMER_ID", newCustomerID);
rs.updateString("NAME", name);
rs.updateString("ADDRESSLINE1", address1);
rs.updateString("ADDRESSLINE2", address2);
rs.updateString("PHONE", phone);
rs.updateString("EMAIL", email);
rs.updateRow();
JOptionPane.showMessageDialog(this, "Updated");
} catch(SQLException err){
JOptionPane.showMessageDialog(this, err.getMessage());
}
}
ResultSet
interface also contains a method to update a row with database changes, if the ResultSet is sensitive to change.
rs.refreshRow();
refreshRow()
--> Refreshes the column values of that row with the latest values from the database.