File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to  delete and update sql table through JTable  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to  delete and update sql table through JTable  " Watch "How to  delete and update sql table through JTable  " New topic
Author

How to delete and update sql table through JTable

Narendra kodli
Greenhorn

Joined: Dec 24, 2011
Posts: 22
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

Pierre Sugar
Ranch Hand

Joined: Dec 08, 2002
Posts: 62

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


Pierre
Narendra kodli
Greenhorn

Joined: Dec 24, 2011
Posts: 22
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.
Cole Terry
Ranch Hand

Joined: Nov 23, 2011
Posts: 45
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

Joined: Dec 24, 2011
Posts: 22
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

Joined: Dec 08, 2002
Posts: 62

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


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Why use a PropertyChangeListener? With TableModelListener you can already do this. Simply listen for TableModelEvents with a type of TableModelEvent.UPDATE.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Pierre Sugar
Ranch Hand

Joined: Dec 08, 2002
Posts: 62

TableModelListener is definitely the better solution.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to delete and update sql table through JTable
 
Similar Threads
JTable(!!!)
adding a blank row to a JTable
Displaying sql qry in a JTable
Jtable
jtable