This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populating JTable from Oracle DB

 
Vincent Martinez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need some guidance on how I can populate a JTable from a DB. I think I may have to extend AbstractTableModel and retrieve the data in this implementation. Then pass that to the JTable? I am not sure. I just want to know the best way to show the users this table that has a fixed number or rows and cells. Any code reference or other ideas would be greatly appreciated. Thanks.
I already can connect to the DB and execute queries. I just don't know what to do with the recordset once I have it.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just what you said. Put the data into the Model and add it the the JTable.
 
Vincent Martinez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I need to extend the AbstractTabelModel or is there another TableModel I can use? Thanks for you help.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could look at DefaultTableModel. Or you could just use the JTable constructor which take either Object[][] or Vector and leave it at that. It really all depends on what you have to do.
The Java tutorial on tables is pretty good. It should help you decide what path is best for your requirements.
 
Matt Hansen
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the DefaultTableModel and then call setDataVector to populate it. See http://java.sun.com/j2se/1.3/docs/api/javax/swing/table/DefaultTableModel.html#set DataVector
Or, if your table is static just pass the data in using the constructor JTable(Object[][] rowData, Object[] columnNames) and then you don't have to worry about the model.
[This message has been edited by Matt Hansen (edited September 27, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic