• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • 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
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank You Ryo , that is really a big help.
Archana
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!