aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Useing Jtable to Inser data in a MySQL table on Clik of a Jbutton. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Useing Jtable to Inser data in a MySQL table on Clik of a Jbutton." Watch "Useing Jtable to Inser data in a MySQL table on Clik of a Jbutton." New topic
Author

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

Baptuu Ghosh
Greenhorn

Joined: Jun 17, 2013
Posts: 4
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


Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

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.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Baptuu Ghosh
Greenhorn

Joined: Jun 17, 2013
Posts: 4
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

Joined: Jun 17, 2013
Posts: 4
Hi Raghunathan,

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

Baptuu
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2171
    
    7
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

Joined: Jun 17, 2013
Posts: 4
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

Joined: Oct 16, 2003
Posts: 1076
    
  10

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Useing Jtable to Inser data in a MySQL table on Clik of a Jbutton.