• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Columns on JTable

 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2565
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2565
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can also use the ResultSetMetaData class
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic