Chris,

I was looking at that earlier, wondering why it was put in there in the
first place.  It just doesn't fit in.  Sometimes you just hate to inherit
someone else's mess.

While there is another school of thought telling me to re-write the entire
DAO (which I could be willing to later on) for right now, I want to just
tweak and get it to work more efficiently on the server.  I think this is a
HUGE improvement over what was there and what actually was going on.  Thank
you sir!

On Fri, Oct 30, 2009 at 5:14 PM, Christopher Schultz <
ch...@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Josh,
>
> On 10/30/2009 4:31 PM, Josh Gooding wrote:
> > 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(); }
> >         }
> >     }
>
> I think the finally block does everything you want. You don't really
> even need the try portion... I would further simplify it to:
>
> public static void closeResources(ResultSet rs)
>   // No 'throws' clause... no reason to throw an exception
>  // here because there's nothing you can do about it: just log it.
> {
>   Statement s = null;
>   Connection conn = null;
>   try
>   {
>      s = rs.getStatement();
>   }
>    catch (SQLException sqle)
>   {
>      sqle.printStackTrace();
>   }
>
>   if(null != s)
>   {
>      try
>      {
>          c = s.getConnection();
>       }
>      catch (SQLException sqle)
>      {
>         sqle.printStackTrace();
>      }
>   }
>
>   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(); }
> }
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkrrV1EACgkQ9CaO5/Lv0PDhpQCfSABY67rM0YjoEjXn5H/jT1tQ
> ZJIAoLfPGl3Ewk90y6E11sglZkSDaAWH
> =Lcer
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

Reply via email to