How to update Jtable used data from a database?

Asked

Viewed 961 times

1

I created in Netbeans a customer registration and movie registration system (simulating a video rental company). I have 3 Java files: Video Rental (main), Client and Movie. In Client and Film, I make the connection to the database, insert the values, all cute. The question is: How to do, when I run the application, and access Client/Movie, to JTable is filled in with pre-stored database data.

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

  • 1

    See if the answer in that question is what you’re looking for.

  • Actually, I don’t know. I’m kind of new, but from what I saw in that question, the guy’s already halfway through what I wanted to do, which is to do the search, and there he’s just trying to get in. But I don’t know how to search, nor how to insert rsrs.

  • You are using Abstracttablemodel?

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 stores the rows and columns of the Tablemodel.

4) In your application, initialize your tableModel by passing the database data list.

5) pass the model to the table -> table.setModel(yourModel)

Look at this another answer in more detail!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.