• Post Reply Bookmark Topic Watch Topic
  • New Topic

update SQL through JTable  RSS feed

 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
can someone give me a code snippet on how to update my database through a JTable? in my JTable, can i have a "edit" button so that when i click on that button, it edits the fields in the database? is that possible?
thank you,
Rockster
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rocky,
That could turn out pretty complicated. You need to read a table with SQL SELECT query, populate the result set into a JTable, maybe keep a copy of the origianl values so you can see what fields have been edited by the user, and then send an UPDATE SQL which updates the database. Each of those steps could be a bit tricky, but maybe there is a commercial or free product available to do all this??
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's actually not that tricky, but it is beyond simple enough to post in a "code snippet". There is actually an Example of this that comes with the JDK install, if you installed the Examples. I'll see if I can locate it and let you know which one it is...
In the meantime, I would suggest reading up on the TableModel API's at http://java.sun.com. You will want to get very intement with those.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, the demo should be located something like this.
$JDK_INSTALL\demo\jfc\TableExample.
All the src code is there.
 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi gregg,
how do i open that up? sorry i'm quite new to all this swing/sql stuff...
rockster
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!