Re: PreparedStatements, LIKE and the % operator - Mailing list pgsql-jdbc

From j.random.programmer
Subject Re: PreparedStatements, LIKE and the % operator
Date
Msg-id 26855.31012.qm@web32014.mail.mud.yahoo.com
Whole thread Raw
In response to Re: PreparedStatements, LIKE and the % operator  (Dave Cramer <pg@fastcrypt.com>)
List 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 by date:

Previous
From: Dave Cramer
Date:
Subject: Re: PreparedStatements, LIKE and the % operator
Next
From: Thomas Kellerer
Date:
Subject: Re: PreparedStatements, LIKE and the % operator