Re: PreparedStatements, LIKE and the % operator

Поиск
Список
Период
Сортировка
От j.random.programmer
Тема Re: PreparedStatements, LIKE and the % operator
Дата
Msg-id 26855.31012.qm@web32014.mail.mud.yahoo.com
обсуждение исходный текст
Ответ на Re: PreparedStatements, LIKE and the % operator  (Dave Cramer <pg@fastcrypt.com>)
Список pgsql-jdbc
Hi:

> Craps out how ?
>
> bar = like %?%

That was a typo. Sorry. I wasn't using '=' at all.

>
> bar like '%?%'
> is closer to the correct syntax

That's what I was doing. The driver gives this error:

-----------------------------
org.postgresql.util.PSQLException: The column index is
out of range: 1, number of columns: 0.
    at
org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:52)
    at
org.postgresql.core.v3.SimpleParameterList.setStringParameter(SimpleParameterList.java:117)
    at
org.postgresql.jdbc2.AbstractJdbc2Statement.bindString(AbstractJdbc2Statement.java:2118)
    at
org.postgresql.jdbc2.AbstractJdbc2Statement.setString(AbstractJdbc2Statement.java:1241)
    at
org.postgresql.jdbc2.AbstractJdbc2Statement.setString(AbstractJdbc2Statement.java:1227)
....etc........
--------------------------------

I hacked around a bit and finally said:

.... bar like ? and foo like ?

ps.setString(1, "%" + myvalue + "%")
ps.setString(2, "%" + my_other_value + "%")

That worked but it's a bit counter-intuitive.

Best regards,
--j



____________________________________________________________________________________
Don't get soaked.  Take a quick peak at the forecast
with the Yahoo! Search weather shortcut.
http://tools.search.yahoo.com/shortcuts/#loc_weather

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

Предыдущее
От: Dave Cramer
Дата:
Сообщение: Re: PreparedStatements, LIKE and the % operator
Следующее
От: Thomas Kellerer
Дата:
Сообщение: Re: PreparedStatements, LIKE and the % operator