onlyforthis
onlyforthis

Reputation: 446

How to auto-refresh a JTable bound to Mysql database after insert using NetBeans

I'm working on a project in NetBeans.

I have a Jtable which i bound to my database and there is a form that I use to insert data.

I want the records in the table to be refreshed with each insert.

How can I do that?

Upvotes: 1

Views: 2991

Answers (3)

Rushab Narhar Ambre
Rushab Narhar Ambre

Reputation: 9

Please try the following code:

if you want update the table on button click or on event of any component you have to put the code in the event

  • the list generated should be Observable checked

code

udetailsList.clear();
udetailsList.addAll(udetailsQuery.getResultList());

Upvotes: 0

onlyforthis
onlyforthis

Reputation: 446

I should simply select the table and go to the navigator window. Under "Other Components" there is the list that was created after the binding and contains the table records (you should know its name). Right click on the list > Properties > check "observable".

Upvotes: 1

camickr
camickr

Reputation: 324147

I want the records in the table to be refreshed with each insert.

Then your "insert" logic need to do two things:

  1. insert the data into the database
  2. insert the data into the JTable. This is done by using the addRow(...) method of the DefaultTableModel. You get the data from the form, create a Vector to contain the data for each column then you add the Vector to the model.

Upvotes: 1

Related Questions