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]
# 1
You can't pass a ResultSet or any other object from a javabean to jsp file. Since javabean only work with certain data types that can converted from a string. In your case, you may choose another way other than using javabean.
echojiang at 2007-6-29 1:30:22 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
try to make the return type a vector public Vector getVector(parameters){Vector myVector = new Vector();populate the vector return myVector;}
stephensutherland at 2007-6-29 1:30:22 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

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.

gtb181 at 2007-6-29 1:30:22 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...