Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes How to update changed data into the Database by using JTable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to update changed data into the Database by using JTable?" Watch "How to update changed data into the Database by using JTable?" New topic
Author

How to update changed data into the Database by using JTable?

Ches Starinskis
Greenhorn

Joined: May 01, 2013
Posts: 2

Hello coderanch Forum users.

I would like to ask couple of questions.

I currently able to get the data from the Database and display it in JTable. In addtion, I would like to update the data in the Database that has been modified in the JTable but I don't know how to do it. I found some of the examples what other people did but they did not work for me.

So my question is this: Does it matter how you getting and storing data from the Database?? I currently using Array of String


to store and pass data from the Database and converting the Array in to the Vector and display the data using a


for my JTable.

I know about different methods that can be used to do it but I don't know which is one is better be useful for my situation.

I will be highly appreciated to get some advice or tutorial.

Thanks.

Ducky

P.S. If any one need a code of the methods I use to get data from the Database I will be happily to post them.

Edit

Here an example of the code I use to get the date from the Database in to the JTable
I using a Client and Server architecture for my application: without a proper networking between them.

Server Class
This method will query the Database and automaticly finds out what data is in the table and stores it in Array of String: You can correct me if I get thet part wrong.


Client Class
Then inside of the Client Class Server Object is created and and uses the getDBGrades() from the Server to store it. Correct me if I'm wrong


Staff GUI Class
Then in GUI Class it creates an object of the Client class and uses it methods to put it to the Vector and insert the data into the JTable using DefaultTableModel

When it all done all data is obtained and displayed on the JTable.
User can edit the data inside of the JTable. In addition, I want to allow send modified data back to the Database but I don't how really do it .

I found some example code how to do it in this forum but did not work for me or don't know how to modify it to my needs.
I can attach or send my project files if needed.

P.S. I'm Student don't have a lot of experiences with Java.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3438
    
  47

Welcome to the Ranch!

There is a slight problem with representing all values as Strings. If the value is originally a number in the database, you must convert it to String first, and, after the user edits it, back to a number before writing it to the database. This might lead to loss of precision of the numbers, or problems with decimal separators, and surely will make sorting the table difficult. The correct way is to keep the data in the table model using their proper data types, as JTable supports displaying and editing various types of data, even non-standard ones. See the JTable tutorial for details.

What problems do you encounter when trying to update the database? If you have some code, post it here and describe your difficulties. You might also find some inspiration in this post.
Ches Starinskis
Greenhorn

Joined: May 01, 2013
Posts: 2

@Martin Vajsar

Here some example code for you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to update changed data into the Database by using JTable?
 
Similar Threads
JTable issues
JTable(!!!)
JTable
How to display Database Table DATA in jTable
Wanted: conceptual tutorial on JTable