PreparedStatements, LIKE and the % operator

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

I am using postgres 8.2 with the 8.2.504 jdbc3 driver.

I am getting data from a untrusted source. Hence a
prepared
statement. I also need a partial match.

String query =  " select * from table_foo where bar =
LIKE %?% "
PreparedStatement ps = con.prepareStatement(query);
ps.setString(1, "haha");
....

This craps out when run. Try adding single quotes
before and
after the: %?%

String query =   " select * from table_foo where bar =
LIKE '%?%'  "
PreparedStatement ps = con.prepareStatement(query);
ps.setString(1, "haha");
...

This craps out too.

A quick search of the archives doesn't shed light on
this issue. I
don't need a JDBC escape since I want to use a % char.

So how do I use LIKE within a prepared statement ? I'm
sure I'm
missing something obvious here....

Best regards,
--j





____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html

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

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