Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Passing ResultSet to JSP

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly what is your "java-file" A stand alone application, a servlet, a JavaBean???
Bill
 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 http://www.fdsapi.com. The FormattedDataSet also has methods to convert a ResultSet into HTML with very little code.
 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic