Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38750
| X-Received | by 2002:a37:47c4:: with SMTP id u187mr197171qka.18.1551371648266; Thu, 28 Feb 2019 08:34:08 -0800 (PST) |
|---|---|
| X-Received | by 2002:a25:5306:: with SMTP id h6mr265297ybb.102.1551371648075; Thu, 28 Feb 2019 08:34: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!m21no4820286qta.0!news-out.google.com!y15ni2185qta.0!nntp.google.com!m21no4820279qta.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.java.programmer |
| Date | Thu, 28 Feb 2019 08:34:07 -0800 (PST) |
| In-Reply-To | <f71c1d05-cc27-4ecb-bea0-c32f03cd698e@googlegroups.com> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=84.74.101.34; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r |
| NNTP-Posting-Host | 84.74.101.34 |
| References | <slrnq7dcgo.cfl.avl@logic.at> <709a1f3b-fc99-4bd0-a8b8-866092bb7ae9@googlegroups.com> <slrnq7dnnu.cfl.avl@logic.at> <8e1597a2-5c18-4fd1-83a4-7667e4d11e77@googlegroups.com> <slrnq7fkg8.cfl.avl@logic.at> <23a8128b-5c54-45ba-bfd0-2f7dda078517@googlegroups.com> <fdb81cf4-61e8-4b09-a62f-c97253f23550@googlegroups.com> <f71c1d05-cc27-4ecb-bea0-c32f03cd698e@googlegroups.com> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <692da128-9302-41cf-a8f7-2a2a5903bf82@googlegroups.com> (permalink) |
| Subject | Re: it's Closeable, but I don't want to close() it yet. |
| From | bursejan@gmail.com |
| Injection-Date | Thu, 28 Feb 2019 16:34:08 +0000 |
| Content-Type | text/plain; charset="UTF-8" |
| Lines | 65 |
| Xref | csiph.com comp.lang.java.programmer:38750 |
Show key headers only | View raw
See also:
Must JDBC Resultsets and Statements be closed
separately although the Connection is closed afterwards?
https://stackoverflow.com/q/4507440/502187
The clean OO-solution, in case you dont need
the result set later, is to use try-with-resources statement.
I dont recommend using result sets later, since
database systems usually have a dead man's handling.
There can be timeouts on all kind of layer levels.
Usually these tomeouts have a special error code,
and you should then do retry. It could be that your
connection pooling product does this already for you.
But it might not apply to result sets.
So somehow the eclipse warning makes sense.
On Thursday, February 28, 2019 at 5:24:29 PM UTC+1, burs...@gmail.com wrote:
> Actually you use try (resource), which does automatically
> always a close. Its internally implemented with try finally
> and does exceptiong piggy packing.
>
> But JDBC says, if you close a statement, I guess result
> sets are also closed. And if you close a connection, statements
> are also closed. So what is this fuzz about?
>
> What would be helpful, if the warning from the IDE would
> be shown as well. Could the OP please give the full test case,
> including its outcome?
>
> On Thursday, February 28, 2019 at 3:52:24 PM UTC+1, Eric Douglas wrote:
> > 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();
> > }
> > }
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-27 15:51 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-27 08:48 -0800
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-27 19:03 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-27 11:09 -0800
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-28 12:20 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 06:19 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 06:52 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 08:24 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 08:34 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 09:00 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 11:12 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:26 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 11:33 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:37 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 11:41 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:48 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 12:51 -0800
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-01 08:47 +0000
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-01 09:31 +0000
Re: it's Closeable, but I don't want to close() it yet. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-03-03 02:01 +0100
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-04 09:38 +0000
Re: it's Closeable, but I don't want to close() it yet. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-03-04 12:26 +0100
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-05 14:34 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-03-05 07:34 -0800
Re: it's Closeable, but I don't want to close() it yet. Arne Vajhøj <arne@vajhoej.dk> - 2019-03-04 13:59 -0500
Re: it's Closeable, but I don't want to close() it yet. Marcel Mueller <news.5.maazl@spamgourmet.org> - 2019-02-28 08:30 +0100
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-28 19:10 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:34 -0800
Re: it's Closeable, but I don't want to close() it yet. Marcel Mueller <news.5.maazl@spamgourmet.org> - 2019-02-28 22:24 +0100
Re: it's Closeable, but I don't want to close() it yet. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-02-28 23:25 +0100
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-01 09:43 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 12:11 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 13:49 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 13:52 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 13:59 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 16:17 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 12:26 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 13:44 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-03-01 07:40 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-03-01 08:34 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-03-11 06:27 -0700
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-03-11 07:24 -0700
csiph-web