This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes ResultSet to JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ResultSet to JTable" Watch "ResultSet to JTable" New topic
Author

ResultSet to JTable

Cory Lutton
Greenhorn

Joined: May 19, 2004
Posts: 9
I am having a problem understanding how to get a result set into a JTable. I have seen many posts and webpages that describe using a table model to accomplish this, but I am lost as to how that should work. Can someone describe the basics of how to accomplish this?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

What you need to do is create a class that subclasses AbstractTableModel. If you take a look at the JTable Tutorial from Sun they show you how to do this. Then all you have to do is fill that model with the data from your database. Give that a go and if you are still having problems lets see some code and help you out a bit.


GenRocket - Experts at Building Test Data
Cory Lutton
Greenhorn

Joined: May 19, 2004
Posts: 9
Here is my basic design so far...
1. CLASS VAICon - Use this class to setup a connection (drivers and such).
2. Class BOMData - Extend the VAICon class because of the specific data produced from the query(I will repeat this for each type of data).
3. Use BOMData resultset to create 2 vectors (data and labels)to create a JTable.

The part that confuses me is I may need a class for the abstract table model, does this read data from the BOMData class result set... or the vectors I would need to create (passed in). Also using this type of setup...should I make a table model for each class that extends VAICon?? I am dealing with a ERP system with many groups of data so in the end would have something like this???

1. VAICon (connection stuff)
1. BOMData (extends connection gets result set makes vectors)
2. BOMModel extends AbstractTableModel(constructor takes vectors from BOMData) and does ???
3. BOMTable extends JTable(use BOMmodel)

Am I on the right track here? Or would I only need one table model for all data that I get using VAICon and an extended class??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet to JTable
 
Similar Threads
JTable
JTable
JTable
JTable
JTable