Re: Problem escaping, nonstandard use of \\ in a string literal

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: Problem escaping, nonstandard use of \\ in a string literal
Дата
Msg-id D960CB61B694CF459DCFB4B0128514C20267A132@exadv11.host.magwien.gv.at
обсуждение исходный текст
Ответ на Re: Problem escaping, nonstandard use of \\ in a string literal  (Warren Bell <warren@clarksnutrition.com>)
Список pgsql-jdbc
Warren Bell wrote:
>>> I am having a problem with escaping characters after upgrading to
>>> 8.3. I have changed the postgresql.conf file to contain:
>>>
>>> standard_conforming_strings = on
>>>
>>> I am now getting the following error:
>>>
>>> syntax error at or near "S" at character 282
>>>
>>> I am not escaping this character in my code. I am assuming that the
>>> driver is escaping it. I am using the postgresql-8.3-603.jdbc3.jar as
>>> the driver.
>>
>> Could you send a short code sample for your problem?
>> It would make it easier for me to look.
>
> I am using Ibatis and the prepared statement that was being used was
> something like:
>
> INSERT INTO tabel (somestringfield) VALUES (?)
>
> the parameter that was passed was 'Joe\'s'. I also tried E'Joe\'s'. It
> did not like the escaped apostrophe.

The following code runs without problems:

public class WarrenBell {
    public static void main(String[] args) {
        try {
            java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:postgresql:......");
            conn.createStatement().executeUpdate("SET standard_conforming_strings=on");
            java.sql.PreparedStatement stmt = conn.prepareStatement("SELECT * FROM (VALUES(?)) tab(value)");
            stmt.setString(1, "Joe's");
            if (stmt.execute()) {
                java.sql.ResultSet rs = stmt.getResultSet();
                rs.next();
                System.out.println(rs.getString(1));
                rs.close();
            }
            stmt.close();
            conn.close();
        } catch (java.sql.SQLException e) {
            System.err.println("Error " + e.getErrorCode() + " (SQLSTATE "
                    + e.getSQLState() + "): " + e.getMessage());
            e.printStackTrace();
        }
    }
}

It prints the following on standard output:
Joe's

Yours,
Laurenz Albe

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Oliver Jowett
Дата:
Сообщение: Re: Problem escaping, nonstandard use of \\ in a string literal
Следующее
От: Shahaf Abileah
Дата:
Сообщение: Tracing SQL statements per page/request