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 07:27:27 +0200 Organization: Decebal Computing Lines: 58 Message-ID: <87h8x9pfi8.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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="72fb8bea0235c6b94245dccb186de60d"; logging-data="9789"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZnCaQ8sIiEIdxYtns8zRj/xOFSvFTVko=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:DB5NGS6PCVP5VVOMMPGwo0f967c= sha1:5OB1KWii5ZR+DpxMrYp1ny516OY= Xref: csiph.com comp.lang.java.programmer:37226 Eric Douglas writes: > On Sunday, August 13, 2017 at 1:14:17 PM UTC-4, Cecil Westerhof wrote: >> What is wrong about that? A Statement can only have one ResultSet. So >> if you have 10 (independent) ResultSets you have 10 Statements. >> > > Wrong, read the Javadoc. > http://docs.oracle.com/javase/8/docs/api/java/sql/CallableStatement.html > "can return one ResultSet object or multiple ResultSet objects" That is certainly interesting, but that extends PreparedStatement, not Statement. 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)) { I prefer: try (ResultSet rsOldest = SQLite3Conn.executeQuery(OLDEST_USED) ResultSet rsNewest = SQLite3Conn.executeQuery(OLDEST_USED) ResultSet rsCount = SQLite3Conn.executeQuery(OLDEST_USED)) { You can disagree that the second is better as the first, but I prefer the second. Even if I only need one ResultSet, which is most of the time. And certainly when I need 10 ResultSets I would prefer that. >> >> Also: with the not really needed Statements you increase the risk of >> >> bugs. >> > >> > Not sure what you mean by that. >> >> It would not be the first time that someone used similar names for >> different variables and use the wrong one at a certain point. When you >> double your variables, you increase the risk of making a mistake. >> > > It is easy to screw up code if you use variable names like rs1, rs2, > rs3. This is why Java is a wordy language. If they're different purpose > try different names when you get beyond simple test code, rsCustomers, > rsInvoices. Possibly they're just held in one list or map object, or > you're just reusing one variable. I do not have control over the variable names that other people use. It is a bit like: seat belts are not necessary, you just have to make sure you do not bump into something. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof