|
From: Justinus M. <jus...@lb...> - 2003-08-13 19:03:11
|
thanks for these fast replies.
I'll try Colin's approach for now until we migrate to JDBC 3.0.
Cheers
Justinus
Colin Sampaleanu wrote:
> This is wrong. The best mechanism I've seen to handle this is
> something like
>
> ResultSet rs;
> Statement s;
> Connection conn;
> try {
> ...
> rs.close();
> rs = null;
> s.close();
> s = null;
> conn.close();
> conn = null;
> }
> catch (whatever) {
> throw whatever...
> }
> finally {
> DataSourceUtils.closeIfNotNull(rs, s, conn);
> }
>
>
> where closeIfNotNull is a simple util which does oa close on the
> resultset, statement, and connection, respectively, but only if the
> item is not null, and silently swallows SQLExceptions.
>
> In this fashion, you catch and propogate all SQLExceptions on normal
> usage of the resultset, statement, or connection, including the
> closing of those items, but even if there is an exception, the items
> are actually closed...
>
> Regards,
>
> Colin
|