Thread: Closing ResultSet and Statements

Closing ResultSet and Statements

From
"Antony Paul"
Date:
Hi all,
(Sorry if repost. I posted it some days ago but couldn't  found on the list)
1. Is it necessary to close all ResultSet and Statements in PostgreSQL.
2. How to know that a ResultSet is open ?. Any views to query this
information?.
3. Do closing a Statement closes the ResultSet ?.
4. I saw an option of  autocommit = true in the postgresql.conf file. What
is its use. What is the default behaviour if it is commented. If I set this
to true do I have commit on all connections obtained without using a
connection pool ?.

rgds
Antony Paul



Re: Closing ResultSet and Statements

From
Dave Cramer
Date:
Most of these questions have nothing to do with pg, but jdbc in general.

On Mon, 2004-08-23 at 04:24, Antony Paul wrote:
> Hi all,
> (Sorry if repost. I posted it some days ago but couldn't  found on the list)
> 1. Is it necessary to close all ResultSet and Statements in PostgreSQL.
It is generally very good form to close them, however if you close the
statement, the result set will be closed, as per the jdbc spec.
> 2. How to know that a ResultSet is open ?. Any views to query this
> information?.
not really, you either get null from the Statement.execute, or an open
result set
> 3. Do closing a Statement closes the ResultSet ?.
yes, as per spec
> 4. I saw an option of  autocommit = true in the postgresql.conf file. What
> is its use. 
to set autocommit to false, but I would not expect the driver to
function well, I seriously doubt if anyone has tested this thoroughly.

> What is the default behaviour if it is commented. 
if it is commented that is the default

> If I set this
> to true do I have commit on all connections obtained without using a
> connection pool ?.
If this is true you do not have to commit anything. The way to do this
in jdbc is to use Connection.setAutoCommt(false|true);
> 
> rgds
> Antony Paul
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
> 
-- 
Dave Cramer
519 939 0336
ICQ # 14675561
www.postgresintl.com



Re: Closing ResultSet and Statements

From
Dave Cramer
Date:
Antony,

I think you are talking about are two different things. A result set in
jdbc, and a cursor from the backend. Now they could be the same thing if
you used setFetchSize() and the driver was using cursors behind the
scenes.

AFAIK, there is no way to see all the open cursors, however you may be
able to just use ps -auxw | grep post to see your connections.

Dave
On Mon, 2004-08-23 at 10:34, Antony Paul wrote:
> Thank you for the reply.
> I need to know which ResultSets are open and from which connection for
> finding resource leaks. Oracle provides views for this. I found one contrib
> project for oracle type vies. Is that of any use to me.
>
> rgds
> Antony Paul
>
> ----- Original Message -----
> From: "Dave Cramer" <pg@fastcrypt.com>
> To: "Antony Paul" <antonypaul24@hotmail.com>
> Cc: "pgsql-jdbc" <pgsql-hdbc@postgresql.org>
> Sent: Monday, August 23, 2004 7:52 PM
> Subject: Re: [JDBC] Closing ResultSet and Statements
>
>
> > Most of these questions have nothing to do with pg, but jdbc in general.
> >
> > On Mon, 2004-08-23 at 04:24, Antony Paul wrote:
> > > Hi all,
> > > (Sorry if repost. I posted it some days ago but couldn't  found on the
> list)
> > > 1. Is it necessary to close all ResultSet and Statements in PostgreSQL.
> > It is generally very good form to close them, however if you close the
> > statement, the result set will be closed, as per the jdbc spec.
> > > 2. How to know that a ResultSet is open ?. Any views to query this
> > > information?.
> > not really, you either get null from the Statement.execute, or an open
> > result set
> > > 3. Do closing a Statement closes the ResultSet ?.
> > yes, as per spec
> > > 4. I saw an option of  autocommit = true in the postgresql.conf file.
> What
> > > is its use.
> > to set autocommit to false, but I would not expect the driver to
> > function well, I seriously doubt if anyone has tested this thoroughly.
> >
> > > What is the default behaviour if it is commented.
> > if it is commented that is the default
> >
> > > If I set this
> > > to true do I have commit on all connections obtained without using a
> > > connection pool ?.
> > If this is true you do not have to commit anything. The way to do this
> > in jdbc is to use Connection.setAutoCommt(false|true);
> > >
> > > rgds
> > > Antony Paul
> > >
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 8: explain analyze is your friend
> > >
> > --
> > Dave Cramer
> > 519 939 0336
> > ICQ # 14675561
> > www.postgresintl.com
> >
> >
>
--
Dave Cramer
519 939 0336
ICQ # 14675561
www.postgresintl.com