• 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

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

 
Greenhorn
Posts: 2
Python MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
Python MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Martin Vajsar

Here some example code for you
 
I child proofed my house but they still get in. Distract them with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic