Passing Resultset from bean to JSP
Hello,
I'm new to JSP?
When i call a methode in the bean (getTable())from the JSP file....
This methodes gets the entire content of the table to the Resultset in the bean..
ResultSet rs = stmt.executeQuery("SELECT * FROM Calc");
while (rs.next()) {
String n = rs.getString("Name");
String a = rs.getString("Address");
String c = rs.getString("City");
String o = rs.getString("Surface");
String b = rs.getString("Width");
String p = rs.getString("Price");
String m = rs.getString("Amount");
}
return ?
How can i pass the entire Resultset to the JSP file?
i hope this is not a stupid question..
Thanks in advance!
stoneJ
[756 byte] By [
stoneJ] at [2007-9-26 1:31:12]

String n = rs.getString("Name");
String a = rs.getString("Address");
String c = rs.getString("City");
String o = rs.getString("Surface");
String b = rs.getString("Width");
String p = rs.getString("Price");
String m = rs.getString("Amount");
You probably don't want to pass the rs to a jsp directly. Instead you might want to create a business bean which has various states depending on what the user does. One of the states of the business bean would be a realized state in which the bean would ask an access object for the rs and this rs would populate the business bean.
Create a class called business (you can call them anything you want I am just trying to provide an example) in this class created the properties you stated above like Price etc. Create and inialize method in the class which sets the defualt value of each property. Now create a realize method.
So you pass your business bean to your access bean which then gets populated by you result set
public void realize() {
try {
Access accessObj = Access.GetInstance();
accessObj.realizeAccess(this);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
So now your default values of your jsp will be whatever you set you inialize method to and you can do a if then statement on the same jsp to called your business.realize method which will display you rs on your page.