• 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
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Useing Jtable to Inser data in a MySQL table on Clik of a Jbutton.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Please help me to capture data inserted by a user in a Table .

and after that actually Inserting the data in a MySQL table . Please see my code below


 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Baptuu,
Welcome to the Ranch!

I guess you will be adding a button which when clicked would do the save operation. You need to add a getData() method in the table model that would return the data.
(since you are using only an object array you would be better off using DefaultTableModel and creating an anonymous instance to override the isCellEditable method).

You can then call that method and persist it to the database. Also, I would think you have the persistence code completely separate - say having it in a different class altogether.
 
Baptuu Ghosh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Man , Thanks for so quick reply,,, Can you please give me an example code
Please it will be a real help

 
Baptuu Ghosh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raghunathan,

Thanks for your reply , can you please give a example of code please ,,

Baptuu
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see you copied the code from the Swing tutorial. I suggest you read the section from the tutorial on How to Use Buttons for examples of using buttons.

Regarding using the DefaultTableModel you can read the API or search the forum or web for examples.
 
Baptuu Ghosh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys

Please help me to get data and inserting the same in MySQL table ,

Actually I am very new in here netbeans IDE, it will be real help If I could get at least a sample guide code to insert data in MqSql useing Jtable...

Please see my code in below once...


joy

 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ranganathan Kaliyur Mannar wrote: I would think you have the persistence code completely separate - say having it in a different class altogether.



As I have stated earlier, you should write a separate class that will connect to a MySQL database and persist data. You should have a value bean class that represents the entity. You can use JPA to declare this as an @Entity too.
Then, you can deal with this class in your table model. Btw, your implementation of DefaulTableModel has nothing much. Deal with one problem at a time separately and then you can integrate them.

You can learn more about table models from the tutorial
 
reply
    Bookmark Topic Watch Topic
  • New Topic