JDBC Update question (quoted strings) - Mailing list pgsql-jdbc

From Gerry Gattis
Subject JDBC Update question (quoted strings)
Date
Msg-id 1094007567.8130.34.camel@Kernighan.iTeamOne.com
Whole thread Raw
Responses Re: JDBC Update question (quoted strings)
List pgsql-jdbc
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


pgsql-jdbc by date:

Previous
From: "Noah Davis"
Date:
Subject: Re: expected trigger behavior in transactions
Next
From: "David Wall"
Date:
Subject: Re: JDBC Update question (quoted strings)