This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes process resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "process resultset" Watch "process resultset" New topic
Author

process resultset

Tom Caldwell
Ranch Hand

Joined: Oct 09, 2000
Posts: 39
I'm trying to learn JSP by converting one of my JDBC servlets to use JSP(which seems harder than it should be) and I think I've got most of it except for the resultset. The book I have uses
jsp:getproperty but it seems like there must be a better way.?
For example if my bean has this statement >
ResultSet myResult = Stmt.executeQuery("SELECT * table ...
What is the best way to process this in the JSP page? especially if there are a large number(20) of columns in the table?
Thanks, for any help
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The "best" way is to put the query into a helper class (which can be a bean if you like), and call it from the JSP. JSP is intended primarily for presentation (HTML, JavaScript), and putting complex programmer information like SQL in a JSP is asking for trouble.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Tom Caldwell
Ranch Hand

Joined: Oct 09, 2000
Posts: 39
Yes but if "myResult" above is the SQL from the bean how do I call that in JSP? like I would in a servlet by > - while(myResult.next())
Nothing I try works, JSP seems much more confusing to me at the moment than servlets ever did.
Thanks
karim qazi
Greenhorn

Joined: Mar 22, 2001
Posts: 20
all you need to do is create a method like:
public ResultSet getResultSet() throws SQLException{
//your code to execute query here
return resultSet;
}
In your jsp just call the bean like:
jsp:useBean class="yourBean" id="myBean" scope="page"
ResultSet rs = myBean.getResultSet();
Now you have the result set in you jsp page and can do what you want with it.
Hope this helps.

[This message has been edited by karim qazi (edited March 28, 2001).]
[This message has been edited by karim qazi (edited March 28, 2001).]
[This message has been edited by karim qazi (edited March 28, 2001).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: process resultset
 
Similar Threads
ResultSet needs connection?
Simple question about using JDBC to access DB2
Processing ResultSet in JSP
Generically Reading A Resultset
Maximum Open Cursors exceeded... URGENT!!!