wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Columns on JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Columns on JTable" Watch "Columns on JTable" New topic
Author

Columns on JTable

Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
hi there guys. i just want to ask,

i have a database with 7 columns... so using an AbstractTableModel, i can be able to show it on the table...
my question is, what if i only want to show 3 specific columns from the said database on the table. what should i do?
please help. i really need this one...
thanks...
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Jhedzkie Skies wrote:my question is, what if i only want to show 3 specific columns from the said database on the table. what should i do?


Create a TableModel implementation that returns the information of only the columns you'd like to show. Here you can find sample code...


OCJP 6 (93%)
Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
Lorand Komaromi wrote:
Jhedzkie Skies wrote:my question is, what if i only want to show 3 specific columns from the said database on the table. what should i do?


Create a TableModel implementation that returns the information of only the columns you'd like to show. Here you can find sample code...



thanks a lot.
i got that one down.
but, is the AbstractTableModel used in MySQL and from JDBC-ODBC Bridge is different?

Co'z i have the model, i used with MySQL. I tried to make a .accdb Access Database now instead of MySQL but this time,
the model cant show the database from .accdb on the JTable...
i haven't changed a code in my model. It works flawlessly on MySQL but not on Bridge.. please help me again..
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2204
    
    7
but, is the AbstractTableModel used in MySQL and from JDBC-ODBC Bridge is different?


You are NOT using an AbstractTableModel to load the data from any database.

You ARE using a class that extends AbstractTableModel and adds functionality the the AbstractTableModel to support the creation of the model. If your custom class uses a ResultSet as a parameter to create a model, then if should work for all databases.
Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
Rob Camick wrote:If your custom class uses a ResultSet as a parameter to create a model, then if should work for all databases.


it looks like this...



but it wont out the database when with access database. but with sql, it works fine.. >_>
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2204
    
    7
i have a database with 7 columns...


Databases don't have columns. Databases have tables and tables have columns.

I'm not an SQL expert, but it look to me like you are trying to get the column information about a table instead of getting the data from the database. If this is so, then here is the code I use for an Access database:

mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
you can also use the ResultSetMetaData class


Website/Java Games: http://www.chitgoks.com
Tech Blog: http://tech.chitgoks.com
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

Or simply remove the TableColumn objects from the JTable. That way the column is still part of the model but it just won't be shown.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Columns on JTable