RE: where to close statement ?

From: Peter Mount <petermount(at)it(dot)maidstone(dot)gov(dot)uk>
To: "'Guillaume Rousse'" <Guillaume(dot)Rousse(at)univ-reunion(dot)fr>, pgsql-interfaces(at)postgresql(dot)org
Cc: Peter Mount <petermount(at)it(dot)maidstone(dot)gov(dot)uk>
Subject: RE: where to close statement ?
Date: 2000-04-18 14:04:28
Message-ID: 1B3D5E532D18D311861A00600865478C70C4BD@exchange1.nt.maidstone.gov.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Ah, forgot that bit. I put them under finally as it always gets run,
although you have to wrap them in a try{} win finally if the parent
method doesn't throw SQLException.

Peter

--
Peter Mount
Enterprise Support
Maidstone Borough Council
Any views stated are my own, and not those of Maidstone Borough Council.

-----Original Message-----
From: Guillaume Rousse [mailto:Guillaume(dot)Rousse(at)univ-reunion(dot)fr]
Sent: Tuesday, April 18, 2000 2:57 PM
To: pgsql-interfaces(at)postgresql(dot)org
Cc: petermount(at)it(dot)maidstone(dot)gov(dot)uk
Subject: RE: [INTERFACES] where to close statement ?

All right, that's another way to close them, but it doesn't answer to
the
question : where to close ?

Le mar, 18 avr 2000, Peter Mount a écrit :
> I test each one, and if not null, then call close, ie:
>
> if(rs!=null) rs.close();
>
> This allows for the statement to be open, but the failure being with
the
> ResultSet.
>
> Peter
>
> --
> Peter Mount
> Enterprise Support
> Maidstone Borough Council
> Any views stated are my own, and not those of Maidstone Borough
Council.
>
>
>
> -----Original Message-----
> From: Guillaume Rousse [mailto:Guillaume(dot)Rousse(at)univ-reunion(dot)fr]
> Sent: Tuesday, April 18, 2000 1:25 PM
> To: pgsql-interfaces(at)postgresql(dot)org
> Subject: [INTERFACES] where to close statement ?
>
>
> Hi.
> Imagine the foolowing situation: i got one connection, and i have
> several
> preparedStatements to execute, each with different parameters. Is is
> good
> practice to close the connection in a finally() statement. But what
> about
> statements and resultset ? Is there an advantage to close them
> explicitely :
> -in the finally statement, before the connection.close() (see code A)
?
> -in the try statement, between each statement execution for the
> resultset, and
> between each redefinition for each preparedStatement (see code B) ?
>
> code A:
> Connection con=null;
> PreparedStatement stmt=null;
> Resulset rs=null;
>
> try {
> stmt=...
> stmt.set...
> rs=stmt.execute();
> stmt.set...
> rs=stmt.execute();
>
> stmt=...
> stmt.set...
> rs=stmt.execute();
> stmt.set...
> rs=stmt.execute();
> } finally {
> rs.close();
> stmt.close();
> con.close()
> }
>
> code B:
> Connection con=null;
>
> try {
> PreparedStatement stmt=...
> stmt.set...
> Resulset rs=stmt.execute();
> rs.close();
> stmt.set...
> rs=stmt.execute();
> rs.close();
> stmt.close();
>
> stmt=...
> stmt.set...
> rs=stmt.execute();
> rs.close();
> stmt.set...
> rs=stmt.execute();
> rs.close();
> stmt;close();
>
> } finally {
> con.close()
> }
> --
> Guillaume Rousse
> Iremia - Université de la Réunion
>
> Sleep doesn't exists. Just lack of cafeine.
--
Guillaume Rousse
Iremia - Université de la Réunion

Sleep doesn't exists. Just lack of cafeine.

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Hakan Tandogan 2000-04-18 14:21:32 JDBC: Missing Classes?
Previous Message Guillaume Rousse 2000-04-18 13:56:45 RE: where to close statement ?