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: Testing the functionality of sub classes Date: Sun, 20 Aug 2017 16:35:49 +0200 Organization: Decebal Computing Lines: 66 Message-ID: <87o9rae27u.fsf@munus.decebal.nl> References: <87fucnh2wu.fsf@munus.decebal.nl> <87y3qffim5.fsf@munus.decebal.nl> <87pobrf855.fsf@munus.decebal.nl> <87ziaue74o.fsf@munus.decebal.nl> <87valie4xz.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="a3233d099e71e24d901953f13bac9801"; logging-data="24177"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19a6N9K9/ABXS5k7mKGJRziKP9OZr00n5g=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:v94KuuFHdfZxcgZGguwKGXQYNUo= sha1:lVir5nH7TSbtTF4J4t0QHmbQ0oM= X-Homepage: http://www.decebal.nl/ Xref: csiph.com comp.lang.java.programmer:37317 Arne Vajhøj writes: > On 8/20/2017 9:36 AM, Cecil Westerhof wrote: >> Cecil Westerhof writes: >>> Just to satisfy my curiosity I executed (I do not like the formatting, >>> but that is what Eclipse does): >>> try ( >>> Statement stmt = conn.createStatement(); >>> ResultSet rsOne = stmt.executeQuery("SELECT 12 AS twelve"); >>> ResultSet rsTwo = stmt.executeQuery("SELECT 'Hello World!' AS message") >>> ) { >>> System.out.println(stmt); >>> System.out.println(rsOne); >>> System.out.println(rsTwo); >>> } >>> >>> And this gives: >>> org.sqlite.jdbc4.JDBC4Statement@685f4c2e >>> org.sqlite.jdbc4.JDBC4ResultSet@7daf6ecc >>> org.sqlite.jdbc4.JDBC4ResultSet@7daf6ecc >>> >>> So yes, it is like you said: the ResultSet is reused. Is also more >>> logical. I jumped to a conclusion. >> >> With a H2 database I get: >> stat0 >> rs0: null >> rs1: org.h2.result.LocalResult@1bc6a36e columns: 1 rows: 1 pos: -1 > > That is what happens when you try and do unsupported things: you get > undefined/implementation specific behavior. Bad! Nope, it shows that the H2 driver does follow the standards (and the SQLite3 driver does not). The first ResultSet is closed as it should be. You can do an isClosed on it. So it is not null, but displays a null to show you should not use it anymore. I now defined also: case "--twoResultSetsOnStatement": if (parameters.length != 0) { break; } try ( Statement stmt = conn.createStatement(); ResultSet rsOne = stmt.executeQuery("SELECT 12 AS twelve"); ResultSet rsTwo = stmt.executeQuery("SELECT 'Hello World!' AS message") ) { System.out.println(stmt); System.out.println(rsOne); System.out.println(rsTwo); if (!rsOne.isClosed()) { System.out.println("ERROR: First ResultSet is not closed."); } if (rsOne == rsTwo) { System.out.println("ERROR: Statement reuses ResultSet."); } } return true; So it is easy to check if a database driver confirms to this part of the standard. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof