• 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

Using bean after resultset

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can anybody tell me,

how to set the values retrived from select query from a resultset into a bean?

As I know in the bean setter method we do set.

but when we do while(resultset.next()), for 1st loop the values will be set then what? for the next iteration & so on?

the last iteration values will be set only when finish?

How to use bean in this case?
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jyoti Vaskar wrote:how to set the values retrived from select query from a resultset into a bean?

As I know in the bean setter method we do set.

but when we do while(resultset.next()), for 1st loop the values will be set then what? for the next iteration & so on?

the last iteration values will be set only when finish?

How to use bean in this case?


That may depends on what you retrieve in your query. If that contains only one row then you need only one bean instance. Or if it is more than one then if you need to get all those records (i.e: list of beans) then you need to have a List (or any data structure that can hold many objects), populate the bean and add it to your data structure in each iteration. What's the exact issue you are having ? What have you tried so far?
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Too difficult a question for "beginning Java". Moving.
 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to show all the data in a table (obviously a big table containing a huge data).

I have retrived the data into resultset by select query.

My problem now is that, I want to use bean.
Now I dont know how to use bean.

I want to display this data in jsp.

Can anybody please help?
 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Too difficult a question for "beginning Java". Moving.



hey! moving to where?
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jyoti Vaskar wrote:hey! moving to where?

Here

JDBC actually, but you can still follow the thread from its original location.
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jyoti Vaskar wrote:I have retrived the data into resultset by select query.
My problem now is that, I want to use bean.


Do you have a domain class which corresponds to each row of that table ?

Now I dont know how to use bean.
I want to display this data in jsp.


As you said in your original post you may use the setters to set the values of the bean

Simple example:

 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for the code you shown Vijitha, but I do have a very huge data that has to be set in bean.

means see for four coloums say I can set for 1 iteration.

But then what for the next iterations ? How can I get all the values to display in the jsp?

Is that I have to iterate the values for each task such as,

setting into bean,
getting from the bean &
display??

Again next iteration for all above three steps?
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jyoti Vaskar wrote: but I do have a very huge data that has to be set in bean.
means see for four coloums say I can set for 1 iteration.
But then what for the next iterations ? How can I get all the values to display in the jsp?


You should set the list of beans in a suitable scope (perhaps request scope) and in JSP you can get the list of beans, iterate and display them. You are using MVC or any other framework ? If not you should read atleast about MVC.
 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

thank you Vijitha.

I am using MVC framework.

thank you for help & sugessions.
 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking to do something very similar to this myself, this is essentially what I have done, then I have passed the Bean into a requestSetAttribute and retrieved it on the JSP page.



JSP (2.0) unsing JSTL & EL...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic