aspose file tools*
The moose likes JDBC and the fly likes Using bean after resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using bean after resultset" Watch "Using bean after resultset" New topic
Author

Using bean after resultset

Jyoti Vaskar
Ranch Hand

Joined: Jun 30, 2009
Posts: 142

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?


thanks
Jyo
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

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?

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Too difficult a question for "beginning Java". Moving.
Jyoti Vaskar
Ranch Hand

Joined: Jun 30, 2009
Posts: 142
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

Joined: Jun 30, 2009
Posts: 142
Campbell Ritchie wrote:Too difficult a question for "beginning Java". Moving.


hey! moving to where?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Jyoti Vaskar wrote:hey! moving to where?
Here

JDBC actually, but you can still follow the thread from its original location.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

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

Joined: Jun 30, 2009
Posts: 142
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

Joined: Mar 24, 2008
Posts: 3775

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

Joined: Jun 30, 2009
Posts: 142

thank you Vijitha.

I am using MVC framework.

thank you for help & sugessions.
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using bean after resultset
 
Similar Threads
String Values (Please Help)
call a servlet from a jsp????
Exausted ResultSet
Passing ResultSet from a Servlet to JSP
Iteration in JSF, how ?