How to update JTable used data from a database? [closed]

1

I created in NetBeans a system of customer registration and movie registration (simulating a video store). I have 3 Java files: Rental (main), Client and Movie. In Client and Movie, I connect to the database, enter the values, everything cute. The question is: How do I, when I run the application, and access Client / Movie, JTable if it populate with pre-stored database data.

For example: I open the application, insert a data (remembering that what appears in JTable does not come from the database, but a simple getText() ), they go to the database, and close the application. Then when I open it again, JTable is empty, although the data I entered earlier is in the database. I want a way to get the bank's data and throw it in JTable to keep it updated.

    
asked by anonymous 13.05.2015 / 16:58

1 answer

0

1) You need to create a method that returns the list of database elements. 2) JTable has a TableModel, create a class that extends DefaultTableModel. 3) Create a constructor that receives the list of elements and map the rows and columns of the TableModel. 4) In your application, initialize your tableModel by passing the list of bank data.
5) pass the model to the table - > table.setModel (yourModel)

See this other answer in more details!

    
22.06.2015 / 20:52