Currently, I am working on JAVA program, which communicates with DB created with XAMPP. I am using different JPanels to show information from the database and give different options to the user to manipulate data.
I have a class called EmployeePanel which extends JPanel, the code in this class retrieves all the information from the database which is saved in Employee Table and displays in JTable. The problem occurs when I am manipulating with data in my JAVA program. For example when I am calling a command (After deleting an employee from this table )
cl.show(cardwrapper, "Employee");
Information in JTable is not getting updated from DB.
Here is code for Deleting an entry from database.
public void DeleteNandoca(){
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(url, userid, password);
PreparedStatement st = connection.prepareStatement("DELETE FROM `employee` WHERE EMP_FNAME ='"+NandocaToDelete+"'");
st.executeUpdate();
}
catch(Exception e)
{
System.out.println(e);
}
new EmployeePanel();
EmployeePanel.revalidate();
EmployeePanel.repaint();
}
And here is code from ActionPerformed method (when I want to display all Employees after deleting entries in DB
if (e.getSource() == ListEmployeesMenuItem) {
cl.show(cardwrapper, "Employee");
EmployeePanel.revalidate();
EmployeePanel.repaint();
}
Anyone have Idea, how can I make my JTable with updated information every time when the ActionPerformed method is fired?