Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.java.programmer Subject: Re: Not closing a SQL(ite3) connection Date: Sat, 12 Aug 2017 16:44:53 +0200 Organization: Decebal Computing Lines: 55 Message-ID: <87y3qoyhei.fsf@munus.decebal.nl> References: <87a839um2q.fsf@munus.decebal.nl> <874lte1pdj.fsf@munus.decebal.nl> <87bmnlyrx7.fsf@munus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="a1c8c080b2cb6129343ef73ef98e693f"; logging-data="6221"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yeS+nJCOTWYuWaMZ0IcZJE2Eff5XyWm4=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:vRHXHUTs8zXGirYthqOApTa7ryA= sha1:2FI8DRpXS/Yhlv/hiN+i6WvDwA8= X-Homepage: http://www.decebal.nl/ Xref: csiph.com comp.lang.java.programmer:37149 Arne Vajhøj writes: > On 8/12/2017 6:57 AM, Cecil Westerhof wrote: >> This was only for testing purposes. My real code has become: >> @Override >> public void close() throws SQLException { >> boolean closedResultSet = false; >> >> try { >> Statement stmt = resultSet.getStatement(); >> >> resultSet.close(); >> closedResultSet = true; >> stmt.close(); >> } catch (SQLException e) { >> if (closedResultSet) { >> SQLException extException = new SQLException("Could not close Statement after closing ResultSet."); >> >> extException.addSuppressed(e); >> e = extException; >> } >> throw e; >> } >> } >> >> The String will be done with a variable of-course. Beside that: is the >> code OK, or can it be improved? > > I see little value in this over the much more simple: > > @Override > public void close() throws SQLException { > Statement stmt = resultSet.getStatement(); > resultSet.close(); > stmt.close(); > } > > :-) > > The original SQLException should contain sufficient information. I > don't see "Could not close Statement after closing ResultSet." adding > value. Maybe I am gold-plating. I want to make sure that it is clear that it is my function and not a user function where it goes wrong, but of-course: nl.decebal.sql.SQLResultSet.close makes that clear. I probably should remove it. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof