pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Lewis <mark.lewis@mir3.com>
To: Hector Rosas <jeziel.rosas@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: About Connections and PreparedStatements
Date: Wed, 12 Oct 2005 13:01:04 -0700
Message-ID: <1129147265.3999.3.camel@archimedes> (raw)
In-Reply-To: <25266c5c0510121210k8e16cf8id841ba11120aaf8b@mail.gmail.com>
References: <25266c5c0510121210k8e16cf8id841ba11120aaf8b@mail.gmail.com>

If you need to execute the same query many times, then keep the
preparedStatement open and just keep assigning parameters and
(re)executing it.

To get the best performance out of PostgreSQL, you'll need to be running
a relatively recent PostgreSQL version (7.4 or later, I think) along
with a newer JDBC driver, and you'll want to set the prepareThreshold to
something low, like 1 or 2.  See docs here:
http://jdbc.postgresql.org/documentation/80/server-prepare.html

-- Mark

On Wed, 2005-10-12 at 12:10 -0700, 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? Or it doesn't matter if I close the connection, I'm
> using PooledConnection provided by my container (Orion), 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? I mean, is not closing a PreparedStatement a way to increase
> performance? 
> 
> Well, thanks everyone.
> 
> Jeziel.




view thread (3+ messages)

Message-ID: <1129147265.3999.3.camel@archimedes>
Permalink:  ../1129147265.3999.3.camel@archimedes/
Also on:    postgresql.org/message-id/1129147265.3999.3.camel@archimedes

 · 

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: mark.lewis@mir3.com, jeziel.rosas@gmail.com
  Subject: Re: About Connections and PreparedStatements
  In-Reply-To: <1129147265.3999.3.camel@archimedes>
  References: <25266c5c0510121210k8e16cf8id841ba11120aaf8b@mail.gmail.com> <1129147265.3999.3.camel@archimedes>

* 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