pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gerry Gattis <GGattis@iTeamOne.com>
To: pgsql-jdbc@postgresql.org
Subject: JDBC Update question (quoted strings)
Date: Tue, 31 Aug 2004 21:59:27 -0500
Message-ID: <1094007567.8130.34.camel@Kernighan.iTeamOne.com> (raw)

I had to make an unexpected adjustment in a query string in order to
insert 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 = "insert into myTable (lastName) values (?)";
PreparedStatement stm = conn.prepareCall(strInsert);
stm.setString(1, "Smith");
// OK so far
stm.execute();	
//fails with an error message attribute Smith not found

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

It works like a charm.  

It looks like there is a difference in the way the PostGres driver
handles Strings. I have been through several of the documents on the web
site, but 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 with PostGres?

Best regards,
Gerry

view thread (5+ messages)  latest in thread

Message-ID: <1094007567.8130.34.camel@Kernighan.iTeamOne.com>
Permalink:  ../1094007567.8130.34.camel@Kernighan.iTeamOne.com/
Also on:    postgresql.org/message-id/1094007567.8130.34.camel@Kernighan.iTeamOne.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: GGattis@iTeamOne.com
  Subject: Re: JDBC Update question (quoted strings)
  In-Reply-To: <1094007567.8130.34.camel@Kernighan.iTeamOne.com>
  References: <1094007567.8130.34.camel@Kernighan.iTeamOne.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox