tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexandros Kotsiras" <kotsi...@mediaondemand.com>
Subject Using ResultSet object within JSP
Date Fri, 16 Jun 2000 20:04:18 GMT

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

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

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

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

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

  Alex.


±˜˜˜°



Mime
View raw message