Yes, but the code for the AardvarkResourceException is a little strange.
public class AardvarkResourceException extends Exception {
//TODO: eventually change this to a logging exception
public AardvarkResourceException() {
}
public AardvarkResourceException(String message) {
super(message);
}
public AardvarkResourceException(Throwable cause) {
super(cause);
}
public AardvarkResourceException(String message, Throwable cause) {
super(message, cause);
}
}
I could just throw the error and not worry about the custom
ResourceException. I don't understand the added value of this class. I
think the other dev was trying to get fancy instead of using the time he had
wisely.
On Fri, Oct 30, 2009 at 4:40 PM, Propes, Barry L <[email protected]>wrote:
> THIS looks MUCH better.
>
> Initializing the connections and statements to null outside, then going in
> to do the conns and subsequently closing with the try/catch/finally block
> like you have.
>
> What did the stack trace show?
>
> I am still on the dinosaur 4 version, getting ready to very soon upgrade to
> TC 6.
>
> My Data Source reference in the web.xml looks like this
>
> <Resource name="jdbc/myoracle" auth="Container"
> type="javax.sql.DataSource"/>
>
>
> Yours, being on TC6, is likely different, and I think might have to be
> established in the META-INF file. I only have mine one place in the WEB-INF
> folder.
>
> Is the AardvarkResource a previously designated DB datasource class,
> written by the previous developer?
>
>
>
> -----Original Message-----
> From: Josh Gooding [mailto:[email protected]]
> Sent: Friday, October 30, 2009 3:32 PM
> To: Tomcat Users List
> Subject: Re: ConnectionPool question
>
> Barry I changed the code to this:
>
> public static void closeResources(ResultSet rs) throws
> AardvarkResourceException {
> Statement s = null;
> Connection c = null;
>
> try {
> s = rs.getStatement();
> if (s != null) {
> c = s.getConnection();
> }
> rs.close();
> }
> catch (SQLException e) {
> throw new AardvarkResourceException("Error closing resources
> associated with ResultSet", e);
> }
> finally
> {
> if(null != rs) try { rs.close(); }
> catch (SQLException sqle)
> { sqle.printStackTrace(); }
>
> if(null != s) try { s.close(); } catch (SQLException sqle)
> { sqle.printStackTrace(); }
>
> if(null != c)
> try { c.close(); } catch (SQLException sqle)
> { sqle.printStackTrace(); }
> }
> }
>
> No luck using the DataSoruceConnectionFactory though. I am using 6.0.18.
>
> On Fri, Oct 30, 2009 at 4:28 PM, Propes, Barry L <[email protected]
> >wrote:
>
> > Where does it close the connection? Looks like it gets it, but the
> > close part is commented out. The rs gets closed, but the connection gets
> recycled.
> > Theoretically.
> >
> > Seems like you put a finally block down there to try catching/closing
> > the wayward connection.
> >
> >
> > -----Original Message-----
> > From: Josh Gooding [mailto:[email protected]]
> > Sent: Friday, October 30, 2009 1:43 PM
> > To: Tomcat Users List
> > Subject: Re: ConnectionPool question
> >
> > I also found this tid bit lying around. It get's a connection, but
> > doesn't close the statement.
> >
> > public static void closeResources(ResultSet rs) throws
> > AardvarkResourceException {
> > try {
> > Statement s = rs.getStatement();
> > if (s != null) { // ResultSets produced by metadata queries
> > do not have associated statements
> > Connection c = s.getConnection();
> > //s.close();
> > //c.close();
> > ConnectionPool.recycleConnection(c);
> > }
> > rs.close();
> > } catch (SQLException e) {
> > throw new AardvarkResourceException("Error closing
> > resources associated with ResultSet", e);
> > }
> > }
> >
> > It still doesn't close the statement, but closes the connection
> > leaving the statement hanging.... I'll fix and make sure to use it.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>