Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

update rows in jtable

 
Aneresia White
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can update rows in database, but in jTable I see the changes only after I close the application and rerun it. What should I do?
This is my code:
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aneresia,
Welcome to JavaRanch!

I think this is more of a Swing question so I'll move it to our GUI forum.
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your code to refresh the data?
 
Aneresia White
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this and I get the updated data , but the old rows are still there.
But after I rerun the application I get the correct data (the old one+the row updated).Hope you understand what I'm trying to say
So what should I do?
 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
looks a bit better, you forget to move fireTableRowsUpdated method in last line of you code/method ? And you have to include former rows too in fireTableRowsUpdated !
[ December 13, 2008: Message edited by: Mikko Kohtam�ki ]
 
Aneresia White
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no that's not it. I'll show you my problem in pictures.
This is my table before update:
photobucket.com

This is my table after update:
photobucket.com

And what I want is now to add those rows again, just to update the table.
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then don't just add them, but clear the model first: model.setRowCount(0).
Well, that's the simple way, that also handles insertions from outside your application. You could also find the row for each record and update it, but then you miss those inserts.
 
Aneresia White
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh great... thank you so much... it worked
That's what I didn't know, how to clear the model.
And now it seems so obvious. :roll:
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shraddha sawant,
Your post was moved to a new topic.
Split from http://www.coderanch.com/t/416164/GUI/java/update-rows-jtable
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic