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: Sun, 13 Aug 2017 23:18:51 +0200 Organization: Decebal Computing Lines: 48 Message-ID: <871sofrwsk.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; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="1615173a1409002a85fbdd25ac4b9ead"; logging-data="21323"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VvHC3bg8rJn2YS4/zuoqVPxYbEN5kZhY=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:7ZlJFeDN9+9laSPC/XvW+HCgURU= sha1:LzXkmXyvWnfPyfUUmxFxzn7w6/Q= X-Homepage: http://www.decebal.nl/ Xref: csiph.com comp.lang.java.programmer:37204 Arne Vajhøj writes: >> What is wrong about that? A Statement can only have one ResultSet. So >> if you have 10 (independent) ResultSets you have 10 Statements. > > No. > > A Statement can only have one ResultSet at a given time, but a Statement > can have multiple ResultSet's over time. > > Statement stmt = con.createStatement(); > ResultSet rs1 = stmt.executeQuery("..."); > ... > rs1.close(); > ResultSet rs2 = stmt.executeQuery("..."); > ... > rs2.close(); > stmt.close(); > > is a common construct. > > (in newer code it would be one try Statement with two try ResultSet inside) > > There are also the possibility in some databases to execute multiple > SELECT in a single execute/executeQuery and then you will get more than > one ResultSet back. > > This is used like: > > Statement stmt = con.createStatement(); > ResultSet rs1 = stmt.executeQuery("..."); > ... > rs1.close(); > stmt.getMoreResults(); > ResultSet rs2 = stmt.getResultSet(); > ... > rs2.close(); > stmt.close(); Since Java7 we (or at least I) do not program that way anymore. You use try with resources. You only want the ResultSet, but to prevent a resource leak, you need to also create the Statement. That makes my hair stand up on the back of my neck. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof