Path: csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.xdsl-89-1-129-173.netcologne.de!not-for-mail From: Patrick Roemer Newsgroups: comp.lang.java.programmer Subject: Re: Which databases are the most used with Java Date: Tue, 15 Aug 2017 16:14:52 +0200 Organization: news.netcologne.de Distribution: world Message-ID: References: <87y3qovwjb.fsf@munus.decebal.nl> <87tw1bx2c9.fsf@munus.decebal.nl> <87a833wzcx.fsf@munus.decebal.nl> <87pobz9yv5.fsf@munus.decebal.nl> <87h8x9pfi8.fsf@munus.decebal.nl> <877ey5ngtu.fsf@munus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Tue, 15 Aug 2017 14:14:52 +0000 (UTC) Injection-Info: newsreader4.netcologne.de; posting-host="xdsl-89-1-129-173.netcologne.de:89.1.129.173"; logging-data="29811"; mail-complaints-to="abuse@netcologne.de" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.24) Gecko/20100411 Thunderbird/2.0.0.24 Mnenhy/0.7.6.0 X-Mozilla-News-Host: news://news.netcologne.de In-Reply-To: <877ey5ngtu.fsf@munus.decebal.nl> Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:37236 Responding to Cecil Westerhof: > Patrick Roemer writes: > >> Responding to Cecil Westerhof: >>> Earlier I was told that the way to do things was something like: >>> try (Statement stmtOldest = conn.createStatement(); >>> ResultSet rsOldest = stmtOldest.executeQuery(OLDEST_USED) >>> Statement stmtNewest = conn.createStatement(); >>> ResultSet rsNewest = stmtNewest.executeQuery(OLDEST_USED) >>> Statement stmtCount = conn.createStatement(); >>> ResultSet rsCount = stmtCount.executeQuery(OLDEST_USED)) { >> >> Sure about that? I haven't seen any such suggestion in recent threads. >> To the contrary, more than once you have been advised to reuse one >> statement to create multiple result sets in sequence. > > Yes I am sure about that. But probably another thread. I am sure I haven't seen it *in recent threads*. I'd love to see a pointer to that post. >> You seem to insist on Statement being an evil ploy designed by the JDBC >> inventors to force you to write unnecessary boiler plate code when all >> you want is just a ResultSet. Whatever follows from this line of >> reasoning is not likely to be correct or useful, I'm afraid. > > I do not see Statement as an evil ploy. But I think that with try with > resources it is something you do not need explicit anymore. This just doesn't make sense. try-with-resources is just syntactic sugar for a try-catch-finally pattern, the semantics are unaffected. In situations where you really only want a one-shot ResultSet, something like your custom helper #executeQuery() method /may/ make sense. But that would be just as useful or useless as with the "classic" try-catch-finally pattern. In almost all other cases, e.g. when sequencing a number of ResultSets, one should go for reuse of a single, explicit Statement. If only because bluntly creating one statement per ResultSet may be harmful for performance - one cannot know how costly creation and teardown of a Statement is going to be. And again, try-with-resources or try-catch finally doesn't have any impact on this consideration. Best regards, Patrick