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 3719FD7FB0 for ; Wed, 12 Oct 2005 16:50:41 -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 11863-06 for ; Wed, 12 Oct 2005 19:50:38 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [131.203.101.226]) by svr1.postgresql.org (Postfix) with ESMTP id 399C6D7E2E for ; Wed, 12 Oct 2005 16:50:38 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1EPmcX-0001jj-Oz; Thu, 13 Oct 2005 08:50:37 +1300 Message-ID: <434D690C.6030301@opencloud.com> Date: Thu, 13 Oct 2005 08:50:36 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051009) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Hector Rosas Cc: pgsql-jdbc@postgresql.org Subject: Re: About Connections and PreparedStatements References: <25266c5c0510121210k8e16cf8id841ba11120aaf8b@mail.gmail.com> In-Reply-To: <25266c5c0510121210k8e16cf8id841ba11120aaf8b@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008] X-Spam-Level: X-Archive-Number: 200510/47 X-Sequence-Number: 13978 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