• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

How to delete and update sql table through JTable

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello dear friends, i am newbie to this java forum, i have a problem given below

I want to do delete and update operations for sql table through JTable using swings, i am able to display the sql table in JTable but unable to do delete and update queries through JTable which should be reflected in sql table.

please help me

 
Ranch Hand
Posts: 62
Ruby Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume you retrieve data from a database and want to display the data in a JTable. If so forward the data to your table model and invoke fireTableDataChanged(). The old data will be cleared and replaced by the new data.
HTH
Pierre
 
Narendra kodli
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply...
Yes i can display table in jtable but my problem is to perform delete and update operation of sql through jtable.i.e jtable cells should act like text box.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Narendra kodli wrote:Hello dear friends, i am newbie to this java forum, i have a problem given below

I want to do delete and update operations for sql table through JTable using swings, i am able to display the sql table in JTable but unable to do delete and update queries through JTable which should be reflected in sql table.

please help me



There is no direct way to sync the data in the JTable with one in the database. At least you must write some code: update the database according to data of the table's model.
 
Narendra kodli
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www2.sys-con.com/itsg/virtualcd/Java/archives/0702/hendry/index.html#source

from above link i got code for jtable but it still not working for me, can any one help.
 
Pierre Sugar
Ranch Hand
Posts: 62
Ruby Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Implement the setValueAt() method in your table model. In setValueAt() fire a property change to inform listeners on changes. In the listener class update your database with new values.

setValueAt() in your table model



Listen on changes in your listener class and update the database


 
Sheriff
Posts: 22662
127
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
Why use a PropertyChangeListener? With TableModelListener you can already do this. Simply listen for TableModelEvents with a type of TableModelEvent.UPDATE.
 
Pierre Sugar
Ranch Hand
Posts: 62
Ruby Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
TableModelListener is definitely the better solution.
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic