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: Sun, 13 Aug 2017 00:30:14 +0200 Organization: Decebal Computing Lines: 39 Message-ID: <87h8xcxvux.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 Injection-Info: mx02.eternal-september.org; posting-host="1615173a1409002a85fbdd25ac4b9ead"; logging-data="29409"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//MratdLQYLgQKKPk3SmriU3rvXo/XYO0=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:d6fzJ+/crJFsZ8vQgekHWWq1TwQ= sha1:6/Me3+dOB4KY1db3pxvvMePitDk= Xref: csiph.com comp.lang.java.programmer:37155 Martin Gregorie writes: > On Sat, 12 Aug 2017 12:57:40 +0200, Cecil Westerhof wrote: > >> The String will be done with a variable of-course. Beside that: is the >> code OK, or can it be improved? >> > The main one is that with most JDBC drivers, the SQLException that > try...catch intercepts is merely the first SQLEXception in a chain of > SQLExceptions. You miss a lot of information about what went wrong by not > repeatedly calling the current SQLException's getNextException() method > until all members of the chain have been retrieved and their contents > displayed. Alternatively, call SQLException.iterator and use that to > iterate through the SQLException chain. > > If the SQL query was at all complex then the first exception in the chain > may not be particularly helpful because what caused the query to fail is > described further down the chain. On a tip from Arne I already changed the code to: @Override public void close() throws SQLException { Statement stmt; if (isClosed) { throw new SQLException("SQLResultSet is already closed."); } stmt = resultSet.getStatement(); resultSet.close(); stmt.close(); isClosed = true; } That solves this problem? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof