X-Received: by 2002:a0c:b048:: with SMTP id l8mr4397121qvc.52.1551365528828; Thu, 28 Feb 2019 06:52:08 -0800 (PST) X-Received: by 2002:a81:ac50:: with SMTP id z16mr6007037ywj.225.1551365528614; Thu, 28 Feb 2019 06:52:08 -0800 (PST) Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!m21no4613095qta.0!news-out.google.com!o7ni1797qta.1!nntp.google.com!m21no4613086qta.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Thu, 28 Feb 2019 06:52:08 -0800 (PST) In-Reply-To: <23a8128b-5c54-45ba-bfd0-2f7dda078517@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.78.95.177; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H NNTP-Posting-Host: 50.78.95.177 References: <709a1f3b-fc99-4bd0-a8b8-866092bb7ae9@googlegroups.com> <8e1597a2-5c18-4fd1-83a4-7667e4d11e77@googlegroups.com> <23a8128b-5c54-45ba-bfd0-2f7dda078517@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: it's Closeable, but I don't want to close() it yet. From: Eric Douglas Injection-Date: Thu, 28 Feb 2019 14:52:08 +0000 Content-Type: text/plain; charset="UTF-8" Lines: 30 Xref: csiph.com comp.lang.java.programmer:38748 On Thursday, February 28, 2019 at 9:19:24 AM UTC-5, Eric Douglas wrote: > On Thursday, February 28, 2019 at 7:20:35 AM UTC-5, Andreas Leitgeb wrote: > > The Closeable interface does not provide any concept of opening. > > Eclipse just sees a local variable of a Closeable type that > > goes out of scope without .close() being called on it. Now, it is possible to confuse Eclipse. I tried this method and got a warning. Is there a better way to do this? public void testQuery(final String db_connect_string) { try (Connection conn = DriverManager.getConnection(db_connect_string)) { final String queryString = "select * from Log limit 10000 offset ?"; try (PreparedStatement statement = conn.prepareStatement(queryString, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) { int r = 0; int r2 = -1; statement.setInt(1, 0); ResultSet rs = statement.executeQuery(); while (r != r2) { r2 = r; while (rs.next()) { r++; } rs.close(); statement.setInt(1, r); rs = statement.executeQuery(); } rs.close(); } } catch (SQLException e) { e.printStackTrace(); } }