Re: how to Escape single quotes with PreparedStatment

Поиск
Список
Период
Сортировка
От Andrew Hastie
Тема Re: how to Escape single quotes with PreparedStatment
Дата
Msg-id 4E5225B1.1030506@ahastie.net
обсуждение исходный текст
Ответ на Re: how to Escape single quotes with PreparedStatment  (JavaNoobie <vivek.mv@enzentech.com>)
Ответы Re: how to Escape single quotes with PreparedStatment  (JavaNoobie <vivek.mv@enzentech.com>)
Список pgsql-jdbc
I think you're defining the "?" parameter incorrectly for the PreparedStatement.

Try this instead:-

String query="SELECT count(*) over () as ROWCOUNT,
CONSUMER_ID,WENEXA_ID,CONSUMER_NAME,CONTACT_NO,residing_village from
db_consumer WHERE lower(CONSUMER_NAME) LIKE (lower(?))";

query.setString(1,"%Fred%");

Where "Fred" is the string you're searching for.

You cannot use the ? token to substitute part of data value, only a whole value. As you are parameterizing the
"pattern"argument to the LIKE expression which is a String argument, you must pass the complete pattern as a String
parameter.

Hope this helps,
Andrew



On 22/08/11 09:14, JavaNoobie wrote:
> Hi,
> I tried that example but it threw an error as follows.
> org.postgresql.util.PSQLException: ERROR: syntax error at or near "%"
>    Position: 158
>     at
> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
>     at
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
>
> Why could this be happening?
>
> --
> View this message in context:
http://postgresql.1045698.n5.nabble.com/how-to-Escape-single-quotes-with-PreparedStatment-tp4718287p4722528.html
> Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
>

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

Предыдущее
От: JavaNoobie
Дата:
Сообщение: Re: how to Escape single quotes with PreparedStatment
Следующее
От: JavaNoobie
Дата:
Сообщение: Re: how to Escape single quotes with PreparedStatment