• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Columns on JTable

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Rancher
Posts: 3244
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 3244
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can also use the ResultSetMetaData class
 
Marshal
Posts: 22444
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic