• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Updating Database using JTables

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys!

I have a JFrame with a save button and cancel button, a jTable used to display data from my mysql database. I use a jDialog to insert record to the database and my jTable will display the records. However, what I want is this, If I click the cancel button in my JFrame, the recently added records in my database which is displayed in my JTable be deleted, since the cancel button is clicked which voids every addition or editing of the data in the database.

How can I cancel the saved records from the database if the cancel button is clicked. It is like restoring the jtable and its display to its original state when cancel button is pressed.

Thanks..

I'm having a hard time to explain my problem..
Please help.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joshua,
Welcome to JavaRanch!

I'm not sure if your question is about databases or JTables. I'm going to move it to our GUI forum where they know about JTables. (since JDBC is inundated with the promo this week) If it winds up being more about JDBC, someone can move it back.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joshua Ebarvia:
How can I cancel the saved records from the database if the cancel button is clicked. It is like restoring the jtable and its display to its original state when cancel button is pressed.



Either you clear the table and reload from the database (or I guess you could use a cache), or else you keep track of which rows the user added so they can be removed later.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically, you keep track of what you added (by storing the information in some kind of a list) and if the user pressed Cancel, you go through that list and delete those records.

Just remember that your database table has to have a primary key or keys for this to work, otherwise you have no way of getting a record to delete it.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or turn autoCommit off and commit upon saving.
 
reply
    Bookmark Topic Watch Topic
  • New Topic