Skip site navigation (1) Skip section navigation (2)

JDBC prepared statements: actually not server prepared

From: Henner Zeller <henner(at)freiheit(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: JDBC prepared statements: actually not server prepared
Date: 2004-06-20 12:09:29
Message-ID: Pine.LNX.4.56.0406201352020.8921@kupfersulfat.toxine.lan (view raw, whole thread or download thread mbox)
Lists: pgsql-hackerspgsql-jdbc

While tracking down a query with a JDBC prepared statement, I
noticed, that the statement actually wasn't prepared but sent to the
server as 'normal' Statement. In my case, this led to a very slow query
since the normal statement does not propagate the correct type -- in my
case I queried an indexed coloumn of type 'int8', which
was correctly passed to the PreparedStatement with setLong() -- however it
was sent with a different type to the server (the
AbstractJdbc1Statement::m_bindTypes[] are never used in this case).

The reason for this is, that by default, the PreparedStatement is not
configured to use a server side prepared statement. I assume, this is

I fixed this by adding this to my local version (current CVS):

--- org/postgresql/jdbc3/    29 Mar 2004 19:17:12 -0000      1.6
+++ org/postgresql/jdbc3/    20 Jun 2004 11:54:00 -0000
@@ -13,6 +13,7 @@
        public Jdbc3PreparedStatement(Jdbc3Connection connection, String
sql) throws SQLException
                super(connection, sql);
+                setUseServerPrepare(true);

        public BaseResultSet createResultSet (Field[] fields,
java.util.Vector tuples, String status, int updateCount, long insertOID)
throws SQLException
(same for Jdbc2PreparedStatement and Jdbc1PreparedStatement).

If this is the right way to do ? And if so .. could someone apply
this patch ?

Bücher kaufen und Freie Software fördern |


pgsql-hackers by date

Next:From: Tatsuo IshiiDate: 2004-06-20 12:39:48
Previous:From: Andreas PflugDate: 2004-06-20 09:28:26
Subject: Re: Compiling libpq with VisualC

pgsql-jdbc by date

Next:From: Oliver JowettDate: 2004-06-20 13:54:49
Subject: Re: [HACKERS] JDBC prepared statements: actually not server prepared
Previous:From: Dave CramerDate: 2004-06-19 14:30:03
Subject: Re: proposal for CallableStatements to handle multiple out

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group