tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrey Nikiforov <>
Subject Re: Using ResultSet object within JSP
Date Sat, 17 Jun 2000 08:45:28 GMT
Hi Alex,

IMHO It would be not bad to encapsulate all resultset iterations into
the bean. Doing this way U would separate presentation (JSP) from
processing (bean). U could even eliminate html tag creation in the bean using
xml/xsl, but it is another story.

If U R trying to save opened connection object between database
queries it is not good solution in most cases. It's better to reopen
connection before each query using DataSource with Connection Pooling.

Hope this helps.


AK> Hello ,
AK>    my question is not a Tomcat specific question but a JSP/JDBC one.
AK>    Very often  in my Database apps i instantiate a Database bean in a
AK> servlet Controller
AK>    and pass it via Request.setAttribute()   to the JSP file where i get the
AK> ResultSet object from the Bean and loop through it to display the results.
AK>    The JSP bean looks like

AK>    <%
AK>        DbBean dbBean = (DdBean) request.getAttribute("DbBean");
AK>        ResultSet rs = dbBean.getResults() ;
AK>     %>

AK>      <Table>
AK>      <% while( { %>
AK>          <TR><TD><%= rs.getString(1) %></TD>
AK>     etc....

AK>     The problem with this approach is that i of course have to close the
AK> ResultSet, PreparedStatement, and Connection AFTER i display the results.
AK>     In other words i have to call
AK>    <% dbBean.close() %>
AK>    in the end of the JSP file. Resulset, PreparedStatement, and Connection
AK> are defined as class level variables in my DbBean.
AK>    I cannot even close the connection before i finish looping through the
AK> result set.
AK>    The close() method throws SQLException and this exactly is the problem.
AK>    I don't want  try-catch within the JSP files. In general i don't want
AK> methods that throw exceptions within the JSP files.
AK>    Of course i can catch the SQLException within the dbClose() method but
AK> then i cannot handle it at the Browser level because i am within the bean.
AK>    Is this right ? ?

AK>    I hope i was clear enough.
AK>    Any ideas would be appreciated.

AK>   Alex.

AK> ±˜˜˜°

AK> --------------------------------------------------------------------------
AK> To unsubscribe, email:
AK> For additional commmands, email:

View raw message