pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Hector Rosas <jeziel.rosas@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: About Connections and PreparedStatements
Date: Thu, 13 Oct 2005 08:50:36 +1300
Message-ID: <434D690C.6030301@opencloud.com> (raw)
In-Reply-To: <25266c5c0510121210k8e16cf8id841ba11120aaf8b@mail.gmail.com>
References: <25266c5c0510121210k8e16cf8id841ba11120aaf8b@mail.gmail.com>

Hector Rosas wrote:
> Hello, I have a doubt with connections and PreparedStatemens. If I open 
> a connection to Postgres and then request a prepared statement, this 
> will be compiled and reused as long as I don't close the connection 
> right?

As long as you reuse the same PreparedStatement object, yes.

> Or it doesn't matter if I close the connection

If you close a Connection, all PreparedStatements created by that 
connection are implicitly closed.

>, I'm using 
> PooledConnection provided by my container (Orion),

I can't speak for that PooledConnection implementation.. it may do extra 
statement caching, I don't know.

> I want to know if 
> there's an advantage to keep a connections open, in order to reutilize 
> PreparedStatement. Also, I'm closing PreparedStatement after every 
> query, PreparedStatement need to be closed after every query right?

You do not need to close the PreparedStatement after each query.

> I 
> mean, is not closing a PreparedStatement a way to increase performance?

If you close a PreparedStatement, the postgresql JDBC driver will free 
any corresponding server-side resources such as server-side prepared 
statements.

So if you want to avoid the parse/plan cost when reexecuting the same 
query many times, you should reuse the same PreparedStatement object 
without closing it between executions.

-O



view thread (3+ messages)  latest in thread

Message-ID: <434D690C.6030301@opencloud.com>
Permalink:  ../434D690C.6030301@opencloud.com/
Also on:    postgresql.org/message-id/434D690C.6030301@opencloud.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: oliver@opencloud.com, jeziel.rosas@gmail.com
  Subject: Re: About Connections and PreparedStatements
  In-Reply-To: <434D690C.6030301@opencloud.com>
  References: <25266c5c0510121210k8e16cf8id841ba11120aaf8b@mail.gmail.com> <434D690C.6030301@opencloud.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox