Re: Connection and Statement

From: Ned Wolpert <wolpert(at)yahoo(dot)com>
To: nickf(at)ontko(dot)com, ambre(at)ebutec(dot)com, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Connection and Statement
Date: 2001-11-08 16:46:39
Message-ID: 20011108164639.34015.qmail@web13406.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Let me add in the following... (And I would love it if someone could
comment on this since I'm punting somewhat...)

You can return the connection to the pool even if you're not done with
the statement/resultSet provided
1) You're not using a cursor while doing a fetch. (Which is due to #2)
2) You're done with your transaction.
3) You don't use the statement for more querrying anymore.

Say that you completed a select statement, and are about the interate
through the result set. In theory you can return the connection to the
pool. (Though I don't do this myself) But if you have the transaction
open for any reason, and you return the connection you'll find odd things
happening. If you're just doing a select, the most common times this
would happen is with a fetch since you'll call it multiple times.

Also, if you have the statement, you can get the connection from the
statement via the getConnection() method. You prob shouldn't use that
either.

Now, is this good practices? I don't do this personally out of habit.
But I'm very interested in others opinions on if this returning the
connection when you just have to iterate over the results of a select.

--- Nick Fankhauser <nickf(at)ontko(dot)com> wrote:

> > 2. When I use a connection pool which keeps all initialized connection
> > open, when is the earliest time I can put an already retrieved
> > connection back. Can I put the connection back, before I have closed
> > all created statements, or is this not good practice.
>
> Our pool class closes unused connections without closing the statements
> opened for the connection. Since the javadoc for close() says "Releases
> this Statement object's database and JDBC resources immediately instead
> of waiting for this to happen when it is automatically closed.", I took
> that to imply that garbage collection would take care of this if we
> yanked the connection out from under the statement. So far, we've not
> experienced any problems with this approach.

=====
Virtually, | "Must you shout too?"
Ned Wolpert | -Dante
wolpert(at)yahoo(dot)com |
_________________/ "Who watches the watchmen?"
4e75 -Juvenal, 120 AD

-- Place your commercial here -- fnord

__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Christian Meunier 2001-11-08 16:48:15 Re: Storing a tree
Previous Message Nick Fankhauser 2001-11-08 14:56:22 Re: Memory exeception