X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A860A5E4701 for ; Wed, 1 Sep 2004 00:14:51 -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 65391-10 for ; Wed, 1 Sep 2004 03:14:52 +0000 (GMT) Received: from mail1.yozons.com (mail1.yozons.com [206.80.109.179]) by svr1.postgresql.org (Postfix) with ESMTP id ED1B05E4711 for ; Wed, 1 Sep 2004 00:14:43 -0300 (ADT) Received: from rasta (soho2.yozons.com [206.80.109.178] (may be forged)) (authenticated bits=0) by mail1.yozons.com (8.12.8/8.12.8) with ESMTP id i813ElpA010591 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT); Tue, 31 Aug 2004 20:14:47 -0700 Message-ID: <0ab101c48fd1$df0f8690$3201a8c0@rasta> Reply-To: "David Wall" From: "David Wall" To: , References: <1094007567.8130.34.camel@Kernighan.iTeamOne.com> Subject: Re: JDBC Update question (quoted strings) Date: Tue, 31 Aug 2004 20:15:02 -0700 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0AAE_01C48F97.328CD2E0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.5 tagged_above=0.0 required=5.0 tests=HTML_20_30, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200409/1 X-Sequence-Number: 10891 This is a multi-part message in MIME format. ------=_NextPart_000_0AAE_01C48F97.328CD2E0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Why are you using conn.prepareCall() instead of conn.prepareStatement()? I= f you did, it should certainly work as you originally did it. CallableStat= ements are different (I don't use them much, but they are for stored proced= ures, not flat SQL statements). David ----- Original Message -----=20 From: Gerry Gattis=20 To: pgsql-jdbc@postgresql.org=20 Sent: Tuesday, August 31, 2004 7:59 PM Subject: [JDBC] JDBC Update question (quoted strings) I had to make an unexpected adjustment in a query string in order to inse= rt a record into a table. I was would like to know if anyone has a remedy = for this. Here is a short description. String strInsert =3D "insert into myTable (lastName) values (?)"; PreparedStatement stm =3D conn.prepareCall(strInsert); stm.setString(1, "Smith"); // OK so far stm.execute();=20 //fails with an error message attribute Smith not found If I use a Statement and manually construct the query string so it contai= ns the single quotes as follows: String strInsert =3D "insert into myTable (lastName) values ('Smith')"; Statement stm =3D conn.getStatement(); stm.execute(strInsert); It works like a charm.=20=20 It looks like there is a difference in the way the PostGres driver handle= s Strings. I have been through several of the documents on the web site, bu= t have not seen this addressed in any of the configuration articles. The app I am working on needs to work with different RDBMS products. I'm = sure I am not the first person to want to do this. Is there a trick to it w= ith PostGres? Best regards, Gerry ------=_NextPart_000_0AAE_01C48F97.328CD2E0 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable =EF=BB=BF
Why are you using conn.prepareCall() inste= ad of=20 conn.prepareStatement()?  If you did, it should certainly work as you= =20 originally did it.  CallableStatements are different (I don't use them= =20 much, but they are for stored procedures, not flat SQL=20 statements).

David
----- Original Message -----
Fro= m:=20 Gerr= y=20 Gattis
To: pgsql-jdbc@postgresql.org <= /DIV>
Sent: Tuesday, August 31, 2004 7:5= 9=20 PM
Subject: [JDBC] JDBC Update questi= on=20 (quoted strings)

I had to make an unexpected adjustment in a query string i= n=20 order to insert a record into a table.  I was would like to know if= =20 anyone has a remedy for this.  Here is a short=20 description.

String strInsert =3D "insert into myTable (lastNa= me)=20 values (?)";
PreparedStatement stm =3D=20 conn.prepareCall(strInsert);
stm.setString(1, "Smith");

// OK = so=20 far
stm.execute();
//fails with an error message attribut= e=20 Smith not found

If I use a Statement and manually construct the qu= ery=20 string so it contains the single quotes as follows:
String strInse= rt =3D=20 "insert into myTable (lastName) values ('Smith')";
Statement stm =3D= =20 conn.getStatement();
stm.execute(strInsert);


It works like= a=20 charm. 

It looks like there is a difference in the way the= =20 PostGres driver handles Strings. I have been through several of the docum= ents=20 on the web site, but have not seen this addressed in any of the configura= tion=20 articles.
The app I am working on needs to work with different RDBMS= =20 products. I'm sure I am not the first person to want to do this. Is there= a=20 trick to it with PostGres?

Best=20 regards,
Gerry


------=_NextPart_000_0AAE_01C48F97.328CD2E0--