Re: PreparedStatements, LIKE and the % operator

From: "j(dot)random(dot)programmer" <javadesigner(at)yahoo(dot)com>
To: Dave Cramer <pg(at)fastcrypt(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PreparedStatements, LIKE and the % operator
Date: 2007-02-03 05:59:26
Message-ID: 26855.31012.qm@web32014.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Thomas Kellerer 2007-02-03 09:30:46 Re: PreparedStatements, LIKE and the % operator
Previous Message Dave Cramer 2007-02-03 04:37:23 Re: PreparedStatements, LIKE and the % operator