• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interchanging Database columns as rows while displaying in a JTable

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi....., everyone. I need to display database values in a JTable but in a different way. My database table has 2 rows and 3 columns. Is it possible to make 3 rows and 2 columns and display.... I mean to say that is it possible to change columns as rows?? I am using java swing.

Can anyone give me some suggestion. I cannot find any solution. Please provide me some useful solution so that i can continue with my work.

Thank you in advance.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A JTable doesn't know nor care what the data it displays.
It just queries the underlying model to get the data to display.

You can create and provide such a model to the table which will switch the row-column data.
More info on tables here http://download.oracle.com/javase/tutorial/uiswing/components/table.html
 
sum prit
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you sir for your reply. But sir can you give me a more useful suggestion regarding this. Actually i have gone through the given link. It displays hardcoded data, but i need the datas from database and also in different way i.e columns as rows. i am trying but still found myself in the same position. i cannot step forward, please give me more suggestion.

Thank you.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In pseudo code:

1) Make call to DB
2) Prepare a model from this data (hint constructor)
3) Pass this model to the table (hint JTable#setModel())
 
sum prit
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your quick reply and suggestion. I am following this rule only. But i cannot able to prepare a model for the table. can you help me out of it. i am stuck at this point, after that i think i can do it.

Thank you sir.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In psuedo code

1) Connect to DB
2) Form and execute queries
3) Iterate over ResultSet.
4) Create a collection from the ResultSet values (what collection? what kind of objects inside? Depends on your requirement)
5) Pass the collection to the model constructor

In the model:
Imagine a List of Objects is what you created (#4 above)
1) THe model needs to tell how many rows. This would be the number of objects in your List
2) THe model needs to tell how many columns. This would be the number of attributes per object in your collection.
3) The model needs to tell what value per cell. This would be the object at the row index and the attribute at the column index.

Forget the DB part for now. First think and decide what kind of collection you need to have for your application. What kind of objects should go inside it.
Create a dummy collection and try to get it working first. Once you do that, linking to the DB is just a method call away.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sum prit, please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/awt-swing/41131-displaying-database-values-row-jtable-but-not-column.html

I also found two earlier cross posts.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Darryl Burke wrote:sum prit, please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/awt-swing/41131-displaying-database-values-row-jtable-but-not-column.html
I also found two earlier cross posts.



Thanks sum prit for wasting my time.
reply
    Bookmark Topic Watch Topic
  • New Topic