File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Passing ResultSet to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing ResultSet to JSP" Watch "Passing ResultSet to JSP" New topic

Passing ResultSet to JSP

Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
Hi, I want to pass a ResultSet (Query for MySQL) from my java-file to my jsp. And then loop (While rs.Next()) in my jsp-file. Is that possible? I manage to print it out in my console from java-file. Im looking for the shortest way to print it out in HTML.

/ Sebastian<br />No blog, No homepage, No life?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Exactly what is your "java-file" A stand alone application, a servlet, a JavaBean???
Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
Well its a stand alone i guess. I import it in the beginning of the jsp-file. like an package (<%@ page import = "gbook.*" %> . The code looks like this right now.
So instead of having a void method I would like to have a method returning an ResultSet. So i can deal with the RS in the jsp-file.
You dig?
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 862
You can pass a ResultSet to the jsp with any method i.e.
public ResultSet getResultSet() throws SQLException
However the jsp will have to close the connection. ResultSets can't be returned from EJBs either. RowSets don't have this problem.
You can also use my ResultSetConverter object that converts a ResultSet to a 2 dim array (Object[][]). This also is detached from the db connection and so you don't have to close it. See this and more at The FormattedDataSet also has methods to convert a ResultSet into HTML with very little code. - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
I agree. Here's the link:
subject: Passing ResultSet to JSP
It's not a secret anymore!