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: Is this the way to work with try with resources Date: Wed, 09 Aug 2017 07:29:15 +0200 Organization: Decebal Computing Lines: 26 Message-ID: <87k22dux5g.fsf@munus.decebal.nl> References: <87poc6wb9n.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="75662a87a83d79e99d1b79ff65a19ab5"; logging-data="17918"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qAETqyHL9dbES6xVOOMawqUluMZ6fzbY=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:qK8gYsYDS58QBATrFKZss/gzEBE= sha1:4+cjZqYxsqtPpUZAsjImp2vwmIc= X-Homepage: http://www.decebal.nl/ Xref: csiph.com comp.lang.java.programmer:37101 Arne Vajhøj writes: > If you absolutely want to make the code shorter no matter the cost, > then just drop the try and do not put in anything else to call close. Not no matter what the cost. ;-) And certainly not without a try. > And then cross your fingers and pray that whoever implemented the > JDBC driver(s) you are using did read the JDBC specs section > stating that Statement close (called implicit in this case) will > also close ResultSet for that Statement. I now have: try (ResultSet rsTotal = conn.createStatement().executeQuery(COUNT_TOTAL_PROV); ResultSet rsUnused = conn.createStatement().executeQuery(COUNT_UNUSED_PROV); ResultSet rsUsed = conn.createStatement().executeQuery(COUNT_USED_PROV)) { That could go wrong? If so: is there a way to verify if it goes OK, or wrong? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof