On Monday, February 17, 2003, at 05:21 PM, Timothy Barreto wrote:

try { ...
} finally {
  try { rs.close(); rs=null;
        stmt.close(); stmt=null;
  } catch (Exception e){}
}
You need to put rs.close() and stmt.close() in different try blocks. If rs.close() throws an exception stmt.close() may never get called. In the CMP engine I have a utility class that contains a bunch of helper methods for closing db resources. Here is a snippet.

public final class JDBCUtil
{
private static Logger log = Logger.getLogger(JDBCUtil.class.getName());

public static void safeClose(Connection con)
{
if(con != null)
{
try
{
con.close();
} catch(SQLException e)
{
log.error("SQL error", e);
}
}
}
...
}


I have a safeClose method for each resource type. This makes the cleanup code very easy to write as you don't have to check for nulls. For example:

try{
// whatever
} finally {
JDBCUtil.safeClose(rs);
JDBCUtil.safeClose(stmt);
}

-dain



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development


Reply via email to