Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Andreas Leitgeb Newsgroups: comp.lang.java.programmer Subject: Re: Is this the way to work with try with resources Date: Wed, 9 Aug 2017 09:40:11 -0000 (UTC) Organization: A noiseless patient Spider Lines: 25 Message-ID: References: <87poc6wb9n.fsf@munus.decebal.nl> <87lgmtwels.fsf@munus.decebal.nl> Reply-To: avl@logic.at Injection-Date: Wed, 9 Aug 2017 09:40:11 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="92e6e7582d029eb5248e6cf55664ba3c"; logging-data="19277"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yyB5uSN0CqqsBUCcemV2X" User-Agent: slrn/1.0.2 (Linux) Cancel-Lock: sha1:wJJokH5jwai9JSEwKrrDD0KtaRk= Xref: csiph.com comp.lang.java.programmer:37107 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? > 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?