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 12:56:46 +0200 Organization: Decebal Computing Lines: 42 Message-ID: <8760dxuhzl.fsf@munus.decebal.nl> References: <87poc6wb9n.fsf@munus.decebal.nl> <87lgmtwels.fsf@munus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="75662a87a83d79e99d1b79ff65a19ab5"; logging-data="6731"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18u6gyIDAOcIvd6wJyb1NDdlAqsIlGieGw=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:8ExvKSNr4eLYcl3xC/xTAsuXecQ= sha1:hvkuX6noE5yGv7+ppgwKtC60nJ8= Xref: csiph.com comp.lang.java.programmer:37109 Andreas Leitgeb writes: > Cecil Westerhof wrote: >> private static void statistics() { >> try (ResultSet rsTotal = executeQuery(COUNT_TOTAL_PROV); >> ResultSet rsUnused = executeQuery(COUNT_UNUSED_PROV); >> ResultSet rsUsed = executeQuery(COUNT_USED_PROV)) { > > and > >> private static ResultSet executeQuery(String query) throws SQLException { >> return conn.createStatement().executeQuery(query); >> } > > So, if one of the queries fails, what will happen to the statements > created so far? > > Or, rather, what will *not* happen to them? If I interpreted try with resources correctly they are destroyed and nothing is done with them. But that is not a problem in my opinion. It should almost never happen. And I so not see a big win in that when the third is going wrong, the first and second are displayed. Also I think it is very unlikely that the first and second are successful and only the third goes wrong. > >> format = String.format("There are %%,%dd %%-6s proverbs.%%n", >> String.format("%,d", count).length()); >> System.out.printf(format, count, "total"); > > What's the point of determining the length of e.g. "1,234,567" just to > set it as the length for a "%,d", which would obviously produce exactly > that length, anyway? Because I use it for the second and third. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof