Skip to main content

Populating Jtable from database - better way

1 reply [Last post]
Joined: 2010-05-20

Hi All,

I have a table in MySQL database.
Is there a way where I can populate a JTable with values from a java bean obnject, which would be getting the values from MySQL table.

Say I have a table named EMPLOYEE with the following details:
1. ID
2. Name
3. Age
4. Address
5. Dept
6. Phone Number

and my Java bean class is Employee which has the following member variables
1. id
2. name
3. age
4. dept

And my JTable should display only the 4 columns out of 6 from MySQL table.

Also I want the table to be auto-refreshed.. the data should be checked for updation.

Which is the best way to do it from the following:
1. Directly read the values from the table using JDBC connection and populate the values into the JTable and poll it using a timer
2. Read the values into a java bean and use a table model to display those values.

Is there any better way to do it?

I am new to Swing so I am unaware of the performance issues related to it.
Would be very thankful for guiding.

Thanks in adavnce.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-04-17

You're in luck, someone asked the same question [url=]here[/url] >_>.