How do I make a Java ResultSet available in my jsp?

Posted by melling on Stack Overflow See other posts from Stack Overflow or by melling
Published on 2008-12-21T06:27:02Z Indexed on 2010/03/11 20:34 UTC
Read the original article Hit count: 200

Filed under:
|

I'd like to swap out an sql:query for some Java code that builds a complex query with several parameters. The current sql is a simple select.

<sql:query
   var="result"
   dataSource="${dSource}"
   sql="select * from TABLE ">
</sql:query>

How do I take my Java ResultSet (ie. rs = stmt.executeQuery(sql);) and make the results available in my JSP so I can do this textbook JSP?

To be more clear, I want to remove the above query and replace it with Java.

<%
  ResultSet rs = stmt.executeQuery(sql); // Messy code will be in some Controller
%>
<c:forEach var="row" items="${result.rows}">
  <c:out value="${row.name}"/>
</c:forEach>

Do I set the session/page variable in the Java section or is there some EL trick that I can use to access the variable?

© Stack Overflow or respective owner

Related posts about jsp

Related posts about jstl