Re: JDBC Update question (quoted strings)

From: "David Wall" <d(dot)wall(at)computer(dot)org>
To: <GGattis(at)iTeamOne(dot)com>, <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: JDBC Update question (quoted strings)
Date: 2004-09-01 03:15:02
Message-ID: 0ab101c48fd1$df0f8690$3201a8c0@rasta
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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(at)postgresql(dot)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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2004-09-01 03:34:28 Re: JDBC Update question (quoted strings)
Previous Message Gerry Gattis 2004-09-01 02:59:27 JDBC Update question (quoted strings)