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.
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.
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.
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.
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.
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.