I’m using the following code to query a database from my jsp, but I’d like to know more about what’s happening behind the scenes.
These are my two primary questions.
Does the tag access the ResultSet directly, or is the query result being stored in a datastructure in memory?
When is the connection closed?
<%@ taglib prefix='sql' uri='http://java.sun.com/jsp/jstl/sql' %> <sql:query var='query' dataSource='${ds}' sql='${listQuery}'></sql:query> <c:forEach var='row' items='${query.rows}' begin='0'> ${row.data } ${row.more_data } </c:forEach>
Note: I’ve always been against running queries in the jsp, but my result set is too large to store in memory between my action and my jsp. Using this tag library looks like the easiest solution.
Observations based on the source for org.apache.taglibs.standard.tag.common.sql.QueryTagSupport
The taglib traverses through the ResultSet and puts all of the data in arrays, Maps, and Lists. So, everything is loaded into memory before you even start looping.
The connection is opened when the query start tag is encountered (doStartTag method). The results are retrieved when the query end tag is encountered (doEndTag method). The connection is closed in the doFinally method.
It a nutshell, it is absolutely awful.