When using DBTag, how can I ensure that a connection is closed if an
exception condition occurs?

It seems the only way is to enclose each DBTag lib usage with try, catch.

It looks like the attached code below (which is not really pretty).

Is there another way to do it?

Could the tag library ensure the connection is closed? We could for example,
have all jdbc tag operations within the body of the connection tag and thus
reaching the end of that tag would mean close connection?

By the way, it is not possible to enclose everything in a try finally block:
for some reasons I don't understand yet Tomcat complains about
"javax.servlet.ServletException:  _jspService signature
(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletRespo
nse;)V) Incompatible object argument for function call"

Thanks in advance, Thierry.

<%
try
{
%>
<h1>Testing JDBC</h1>
<h2>Opening connection</h2>
<jdbc:connection id="conn1">
<jdbc:url>jdbc:odbc:test</jdbc:url>
<jdbc:driver>sun.jdbc.odbc.JdbcOdbcDriver</jdbc:driver>
</jdbc:connection>

<%
} // end try
catch ( Exception e )
{
%> 

<h2>Closing the database connection</h2>
<jdbc:closeConnection conn="conn1"/>

<%
} // end catch
%>

<h2>Closing the database connection</h2>
<jdbc:closeConnection conn="conn1"/>

Reply via email to