This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to present my resultset in an easy way?

 
Peter Hammar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
label2 doesn't works because, JLabel(int) is undefined. We have JLabel(String). I think that is the problem with label2
 
Peter Hammar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Place a sample code Peter if you dont mind.
 
Peter Hammar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are no variables in the code which I proposed, can you be more specific.
 
Peter Hammar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing pal, you have to separate the presentation logic from business logic. You should use MVC architecture.
 
Peter Hammar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks for the tip, have a nice weekend.
 
krishna Karthikk
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you pal, same to you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic