• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populate JTable With Database Data

 
Joe Mastro
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to populate a JTable from a jButton event with data that I'm retrieving from an sqlite db. I have no trouble connecting to database and populating the 'data' and 'row' vectors but when I try to pass them to my JTable (jtblReqList) it does not seem to populate. I am under the impression that I should be able to popluate the JTable with the data contained in the vectors without using any of the table models. Any help is appreciated....thanks.

 
Paul Clapham
Sheriff
Posts: 21113
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're creating a JTable, but I don't see what that has to do with your GUI. I don't see any code where you add that JTable to any GUI.

Typically what you do is to create a GUI, including a JTable. Then when you get the data from the DB you put it into a DataModel, then update the existing JTable by calling its setModel() method (warning... name of method pulled from unreliable memory). Creating a new JTable is generally pointless as it isn't part of the GUI. Trying to get it into the GUI is also difficult to do, but since setting the data model of the one which is already there works, you don't need to futz with that either.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Joe!
Can you please UseCodeTags from now on? I've added them for you, and you can see how much easier it is to read your code.
 
Joe Mastro
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome, thanks everyone. As Paul stated there was no reason to create a new JTable when I already had one existing on my JFrame. I used the DefaultTable model in Nitin's link and set my JTable (jtblReqList) to the model and this at the very least populated the JTable.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic