pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Wall <d.wall@computer.org>
To: GGattis@iTeamOne.com
To: pgsql-jdbc@postgresql.org
Subject: Re: JDBC Update question (quoted strings)
Date: Tue, 31 Aug 2004 20:15:02 -0700
Message-ID: <0ab101c48fd1$df0f8690$3201a8c0@rasta> (raw)
References: <1094007567.8130.34.camel@Kernighan.iTeamOne.com>

Why are you using conn.prepareCall() instead of conn.prepareStatement()?  If you did, it should certainly work as you originally did it.  CallableStatements are different (I don't use them much, but they are for stored procedures, not flat SQL statements).

David
  ----- Original Message ----- 
  From: Gerry Gattis 
  To: pgsql-jdbc@postgresql.org 
  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 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: <0ab101c48fd1$df0f8690$3201a8c0@rasta>
Permalink:  ../0ab101c48fd1$df0f8690$3201a8c0@rasta/
Also on:    postgresql.org/message-id/0ab101c48fd1$df0f8690$3201a8c0@rasta

 · 

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: d.wall@computer.org, GGattis@iTeamOne.com
  Subject: Re: JDBC Update question (quoted strings)
  In-Reply-To: <0ab101c48fd1$df0f8690$3201a8c0@rasta>
  References: <1094007567.8130.34.camel@Kernighan.iTeamOne.com> <0ab101c48fd1$df0f8690$3201a8c0@rasta>

* 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