X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 07CE6D7EA5 for ; Wed, 12 Oct 2005 17:01:12 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 14915-08 for ; Wed, 12 Oct 2005 20:01:03 +0000 (GMT) Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by svr1.postgresql.org (Postfix) with ESMTP id 56446D7D46 for ; Wed, 12 Oct 2005 17:01:04 -0300 (ADT) Received: from archimedes ([172.16.2.68]) by mir3-fs.mir3.com with Microsoft SMTPSVC(5.0.2195.6713); Wed, 12 Oct 2005 13:04:23 -0700 Subject: Re: About Connections and PreparedStatements From: Mark Lewis To: Hector Rosas Cc: pgsql-jdbc@postgresql.org In-Reply-To: <25266c5c0510121210k8e16cf8id841ba11120aaf8b@mail.gmail.com> References: <25266c5c0510121210k8e16cf8id841ba11120aaf8b@mail.gmail.com> Content-Type: text/plain Organization: MIR3, Inc. Date: Wed, 12 Oct 2005 13:01:04 -0700 Message-Id: <1129147265.3999.3.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-16.3) Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 12 Oct 2005 20:04:23.0493 (UTC) FILETIME=[23D97750:01C5CF68] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.042 required=5 tests=[AWL=0.042] X-Spam-Level: X-Archive-Number: 200510/48 X-Sequence-Number: 13979 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.