Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Re: Updating a JTable

camickrOct 19 2006 — edited Oct 23 2006
I tried every method I could find and ended up just making a function that manually updates each row.
Wrong approach.
I've tried everything I can to get it to display the data.
Its not difficult. The easiest approach is to just replace the model in the table.

table.setModel( ... );

Or, in your case it looks your you model class has a setResultSet(...) method, which you don't invoke when you try to refresh the model.

You executeSQL() method has the line:
model.setResultSet(statement.executeQuery(query));
But in your tableChanged() method you use:
statement.executeQuery("SELECT * from shoppingList");
Why are you attempting to duplicate code? Just invoke the executeSQL() method.

Also, another comment is that you should not be using model.fireTableDataChanged(...). The fireXXX methods should only be invoked from within the TableModel.

So, instead of firing those events it looks like you should just be invoking the executeSQL() method after you do your table inserts.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 20 2006
Added on Oct 19 2006
11 comments
409 views