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 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.
1) Make call to DB
2) Prepare a model from this data (hint constructor)
3) Pass this model to the table (hint JTable#setModel())
Joined: Mar 13, 2011
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.
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.