X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 9FB199FA380 for ; Wed, 13 Sep 2006 14:21:04 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 58837-05 for ; Wed, 13 Sep 2006 14:20:53 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id B086D9FA4CF for ; Wed, 13 Sep 2006 14:20:53 -0300 (ADT) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 13 Sep 2006 10:20:51 -0700 Subject: Re: create tables and prepared statements with params From: Mark Lewis To: Enrique =?ISO-8859-1?Q?Rodr=EDguez?= Lasterra Cc: pgsql-jdbc@postgresql.org In-Reply-To: <6daed2a30609131010q280c628cv66c7d2a73f2ab769@mail.gmail.com> References: <6daed2a30609131010q280c628cv66c7d2a73f2ab769@mail.gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Organization: MIR3, Inc. Date: Wed, 13 Sep 2006 10:20:51 -0700 Message-Id: <1158168051.9657.1272.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-27) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.192 tagged_above=0 required=5 tests=AWL, UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200609/50 X-Sequence-Number: 15768 In 8.x the driver uses "real" server-side prepared statements. In 7.4.x the driver did string replacements before submitting statements to the server. There are pros and cons to server-side prepared statements. They're mostly a very good thing, but you're running into one of the limitations; the driver can only put variables in places where the server allows variables. CREATE TABLE isn't one of those places. Your best bet with the 8.x driver is to perform the string replacement yourself. [Question to the list: this should be on the FAQ. How could I go about submitting patches to the FAQ page?] -- Mark Lewis On Wed, 2006-09-13 at 19:10 +0200, Enrique Rodr=C3=ADguez Lasterra wrote: > get an error when i create a table using preparedstatement with some > parameters "?". >=20 > Is this a non standard function? >=20 > With JDBC 7.4 it runs prefectly but with 8.x no. With 8.x if i don't > use params the table is created without errors >=20 > Here is all the info. >=20 > Regards, Enrique >=20 > Code >=20 > package test; >=20 > import java.sql.Connection; > import java.sql.DriverManager; > import java.sql.PreparedStatement; >=20 > /** > * DB > * > * @version 1.0 > * @since 13-sep-2006 > */ > public class DB { > public static void main(String[] args) { > Connection connection =3D null; > try { > Class.forName("org.postgresql.Driver"); > connection =3D > DriverManager.getConnection("jdbc[tongue]ostgresql://192.168.4.221/canyam= o-test", > "canyamo-test", "canyamo-test"); > PreparedStatement stmt =3D > connection.prepareStatement("create table orders ( id integer not > null, client character varying(15) default ? not null)"); > stmt.setObject(1, "without-name"); >=20 > stmt.executeUpdate();//stmt.execute(); > } catch (Exception e) { > e.printStackTrace(); > } > } > } >=20 > Exception >=20 > org.postgresql.util.PSQLException: ERROR: there is no parameter $1 > at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(Q= ueryExecutorImpl.java:1527) > at org.postgresql.core.v3.QueryExecutorImpl.processResults > (QueryExecutorImpl.java:1311) > at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorI= mpl.java:190) > at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdb= c2Statement.java:452) > at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(Ab= stractJdbc2Statement.java:354) > at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(Abstr= actJdbc2Statement.java:308) > at test.DB.main(DB.java:23) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccesso= rImpl.java:39) > at sun.reflect.DelegatingMethodAccessorImpl.invoke > (DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > at com.intellij.rt.execution.application.AppMain.main(AppMain.java= :90) >=20 >=20 > Versions > JDBC: 8.1.404 > Database: 8.1.4 >=20 >=20 >=20