aspose file tools*
The moose likes Beginning Java and the fly likes How to present my resultset in an easy way? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to present my resultset in an easy way?" Watch "How to present my resultset in an easy way?" New topic
Author

How to present my resultset in an easy way?

Peter Hammar
Ranch Hand

Joined: Mar 01, 2010
Posts: 34
Hi all!

I have a table with only two fields, name and age. How do I present the result in my GUI?



I dont like that way and label2 dont work (its an int).

So, what should I do with the result? Put it in an array and loop over the array and then add each variable to an label? Any code hints on how to do that would be nice.

Regards
Peter
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
label2 doesn't works because, JLabel(int) is undefined. We have JLabel(String). I think that is the problem with label2


There is no rule that we all should know everything. Lets learn few things of everything here.
Peter Hammar
Ranch Hand

Joined: Mar 01, 2010
Posts: 34
krishna anusha wrote:label2 doesn't works because, JLabel(int) is undefined. We have JLabel(String). I think that is the problem with label2


How do I define JLabel2 as an INT?
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
To my knowledge, I will try to minimize the code and reduce the usage of unnecessary variables.


And you should not close the stmt object in while loop.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
No it is not that,you have written the statement like this,

new JLabel(age);

where age is an integer because you have assigned rs.getInt("age") to age variable. It means that age variable is an integer in this case.

JLabel class does not have a constructor named JLabel(int arg).

It has JLabel(String arg)

for reference use this
Peter Hammar
Ranch Hand

Joined: Mar 01, 2010
Posts: 34
Hi and thanks for your help.

I tried your code and now the JLabels dont show up on my JPanel. No errors, though.

Regards
Peter
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Place a sample code Peter if you dont mind.
Peter Hammar
Ranch Hand

Joined: Mar 01, 2010
Posts: 34
Sorry for that, I had forgotten to change a name (age reads alder in my DB).

But is this the "good" way to present the result from a resultset? If I have like 30 different variables, it will be alot of code....
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
There are no variables in the code which I proposed, can you be more specific.
Peter Hammar
Ranch Hand

Joined: Mar 01, 2010
Posts: 34
Ok, I mean, I only get name and age. What if I would like to return length, salary and so on...
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
You can use rs.getString(1) which will retrieve the first column of the resultset. It will be useful when you don't exactly remember the column name.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
If you want to represent the entire columns and rows the labels go on increase.

I don't know any other alternate dude. Hope other ranchers propose a simple way.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
One more thing pal, you have to separate the presentation logic from business logic. You should use MVC architecture.
Peter Hammar
Ranch Hand

Joined: Mar 01, 2010
Posts: 34
Ok thanks for the tip, have a nice weekend.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Thank you pal, same to you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to present my resultset in an easy way?