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: Which databases are the most used with Java Date: Tue, 15 Aug 2017 17:42:05 +0200 Organization: Decebal Computing Lines: 67 Message-ID: <87y3qkn8he.fsf@munus.decebal.nl> 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: 8bit Injection-Info: mx02.eternal-september.org; posting-host="72fb8bea0235c6b94245dccb186de60d"; logging-data="18425"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19S1WspJxB2MblhgLLwCIXCBzYVlnBPvWg=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:B5YEzWpSyFNBK9EjMxzETpKfFak= sha1:84K+xiwjAe+Lh+piN4S+knX3CbY= X-Homepage: http://www.decebal.nl/ Xref: csiph.com comp.lang.java.programmer:37246 Patrick Roemer writes: > 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. I have been a ‘little’ into discussions. So I have to look it up. >>> 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. It of-course depends. I have written programs where I used (a ‘global’) Statement several times, but especially in short lived desktop applications it is different. It all started with a certain point where I needed three ResultSets. Because a Statement can only have one concurrent ResultSet I needed also three Statements. I did not like that. And that is where it all started with. The funny thing is that I do not need the three ResultSets anymore, because while creating the wrapper I also created a function to get a count. And this was where I needed the ResultSets for. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof