On Tuesday 19 February 2002 08:54 pm, Leif Mortenson wrote:
> try
> {
>     Connection conn = getConnection();
>     try
>     {
>         Statement stmt = conn.createStatement();
>         ResultSet rs = stmt.executeQuery(query);
>         // Do something with the ResultSet
>     }
>     finally
>     {
>         conn.close();
>     }
> }
> catch (SQLException e)
> {
>     m_logger.error("Error", e);
> }
> ---

I generally do:

Connection con = null;
Statement st = null;
ResultSet rs = null;

try {
        con = getConnection();
        st = con.createStatement();
        rs = st.executeQuery(sql);
        //blah blah
} catch (SQLExeption e) {
        getLogger().error("Exception: " + sql, e);
} finally {
        try { if (rs != null) rs.close } catch (SQLException e) {}
        try { if (st != null) st.close } catch (SQLException e) {}
        try { if (con != null) con.close } catch (SQLException e) {}
}

Still closing everything but somewhat terse in syntax.
-pete

-- 
peter royal -> [EMAIL PROTECTED]

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to