• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

How to retrieve multiple rows from a ResultSet, when using JSP and Beans-Very Urgent

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all ,
In one of my database driven application I am using the JSP and Java beans.
In my bean I am retrieving mulriple rows from the database depending on the user query.I have all getter and setter methods in the bean.
I want to display those rows in the JSP using getProperty() methods.But in the bean as i am storing the values into the ResultSet the properties are having only final row values init.
How can I call the bean from the JSP and display multiple rows?
I really appreciate any kind of help.
Archana
 
Ranch Hand
Posts: 218
VI Editor Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very likely you only have a single data object bean which you keep calling set() for each row of your result set.
You might want to have a Collection of your bean, or have Collection inside your bean.
Then again, I might be wrong since I don't see your code.
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ryo Thank you fo rthe reply.Here exactly what i want to do.
This is my Java Bean

Here is my Bean code

<%@ page import="com.archana.is_project.bookstore.user.beans.BookDetails" %>
<%@ page import="java.sql.*" %>
<jsp:useBean id="search" class="com.archana.is_project.bookstore.user.beans.BookDetails"/>
<html>
<body>
<%
try
{
search.setRequest(request);
search.retrieveBookDetails();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
%>
<%= search.getAuthorFirstName() %>
<%= search.getAuthorLastName() %>
<%= search.getTitle() %>
<%= search.getPrice() %>
</body>
</html>
 
Wirianto Djunaidi
Ranch Hand
Posts: 218
VI Editor Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I suspected, you only had 1 instance of object
that you keep re-set() your attribute. That's why you get the last data evertime.
What you might want to do is move the book info into separate object, let say Book which has the firstname, lastname, title, price, etc.
And your original object to contains a Collection
of Book, like ArrayList.
For example:
Instead of

You have

And when retrieving from database:

And then in your JSP:

Well the above just for example, hope that's help.
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You Ryo , that is really a big help.
Archana
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic