Thread: Prepare Statement

Prepare Statement

From
"Jie Liang"
Date:
Hi,

I have a question about performance, in SQL commands: there is a
prepare/execute command, document says it will improve the performance
while repeatly execute a statement. In java.sql: there is a
PreparedStatement object, which can store precompiled SQL statement,
document says it can improve the performance also.
If I use java jdbc to connect postgresql database, which one I should
use? Can I use both?


Thanks.



Jie Liang

Re: Prepare Statement

From
"Jie Liang"
Date:
Tom,

Does java.sql.PreparedStatement do the same thing as SQL command
prepare/execute ??
Which one should be used while I am using jdbc talking to postgresql? If
using both, do them help the performance?


Thanks.



Jie Liang

-----Original Message-----
From: Jie Liang
Sent: Monday, June 14, 2004 4:33 PM
To: Tom Lane
Cc: pgsql-sql@postgresql.org; pgsql-jdbc@postgresql.org
Subject: [SQL] Prepare Statement


Hi,

I have a question about performance, in SQL commands: there is a
prepare/execute command, document says it will improve the performance
while repeatly execute a statement. In java.sql: there is a
PreparedStatement object, which can store precompiled SQL statement,
document says it can improve the performance also. If I use java jdbc to
connect postgresql database, which one I should use? Can I use both?


Thanks.



Jie Liang

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Re: [JDBC] Prepare Statement

From
Kris Jurka
Date:

On Mon, 14 Jun 2004, Jie Liang wrote:

> I have a question about performance, in SQL commands: there is a
> prepare/execute command, document says it will improve the performance
> while repeatly execute a statement. In java.sql: there is a
> PreparedStatement object, which can store precompiled SQL statement,
> document says it can improve the performance also.
> If I use java jdbc to connect postgresql database, which one I should
> use? Can I use both?
>

When using JDBC it is best to use the standard Statement/PreparedStatement
interfaces.  It is possible to directly use PREPARE/EXECUTE, but this can
be handled by the driver.  Let me give you a run down of the different
driver versions and their capabilities:

Current released version: can enable using PREPARE/EXECUTE behind the
scenes on PreparedStatement by casting the prepared statement to
PGStatement and issuing setUseServerPrepare.

Current cvs version: can enable using PREPARE/EXECUTE by setting an
execution threshold that will turn it on when reached.  This threshold can
be set at a number of levels, see the following for more information

http://www.ejurka.com/pgsql/docs/cvs/ch09s05.html

Soon to be committed cvs version: can directly use server prepared
statements without using the SQL level PREPARE/EXECUTE.

Kris Jurka