Re: escape string for pgsql (using jdbc/java)?

Поиск
Список
Период
Сортировка
От Oliver Jowett
Тема Re: escape string for pgsql (using jdbc/java)?
Дата
Msg-id 45BD294D.5040002@opencloud.com
обсуждение исходный текст
Ответ на Re: escape string for pgsql (using jdbc/java)?  (Tobias Thierer <t_thierer@yahoo.de>)
Ответы Re: escape string for pgsql (using jdbc/java)?  (Tobias Thierer <t_thierer@yahoo.de>)
Список pgsql-jdbc
Tobias Thierer wrote:
> Kris Jurka wrote:
>
>>>  1.) Is there a built-in method somewhere in the jdbc driver that
>>> escapes
>>>      strings and makes them safe to use in an SQL statement (inside a
>>>      string)?
>>
>>
>> There is org.postgresql.core.Utils#appendEscapedString, but it's not
>> something we support or advertise.  It's really for internal use only.
>
>
> I dislike that this method expects me to tell it whether i have
> standard_conforming_strings set - this kinda defeats the "write once,
> run everywhere" principle.

If you want something portable just use PreparedStatement.setString()
and parameter placeholders. The "preparation" overhead you are worrying
about is not really an issue as the PreparedStatement implementation is
designed to handle one-shot queries as well as reused queries
efficiently .. since PreparedStatement is often used just for parameter
value interpolation to avoid exactly the issues you are encountering.

-O

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

Предыдущее
От: Kris Jurka
Дата:
Сообщение: Re: Strange result from DatabaseMetaData.getTablePrivileges()
Следующее
От: Tobias Thierer
Дата:
Сообщение: Re: escape string for pgsql (using jdbc/java)?