Question

I have 2 simple database query JTable (Client and Server).

Client has all functions like view records, print, save PDF etc. Server auto refresh database records to table with a timer of 30secs. (Not yet implemented.)

My problem is I can display the database records to table with no issue with the following code.

PreparedStatement pst = conn.prepareStatement("SQL");
ResultSet rs = pst.ExecuteQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));

But I wish to implement the auto refreshing of table with the above code with a timer.

Example, I inserted the codes into a methods called public void Update_Records(). How am I supposed to use the timer to call the method to display the records into the table every 30 secs?

Was it helpful?

Solution

You could do:

Timer timer = new Timer(0, new ActionListener() {

   @Override
   public void actionPerformed(ActionEvent e) {
      updateRecords();
   }
});

timer.setDelay(30000); // delay for 30 seconds
timer.start();

Aside: Java naming conventions have methods starting with lowercase and underscores are generally not used so Update_Records becomes updateRecords.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top