pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: j.random.programmer <javadesigner@yahoo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: PreparedStatements, LIKE and the % operator
Date: Fri, 2 Feb 2007 23:37:23 -0500
Message-ID: <37697F6B-C1F1-448D-AFCA-E7C463FBA283@fastcrypt.com> (raw)
In-Reply-To: <895911.8931.qm@web32005.mail.mud.yahoo.com>
References: <895911.8931.qm@web32005.mail.mud.yahoo.com>

Hi

Craps out how ?

bar = like %?%

is invalid

bar like '%?%'

is closer to the correct syntax

Dave
On 2-Feb-07, at 10:58 PM, j.random.programmer wrote:

> 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
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
>                 http://www.postgresql.org/about/donate
>




view thread (5+ messages)  latest in thread

Message-ID: <37697F6B-C1F1-448D-AFCA-E7C463FBA283@fastcrypt.com>
Permalink:  ../37697F6B-C1F1-448D-AFCA-E7C463FBA283@fastcrypt.com/
Also on:    postgresql.org/message-id/37697F6B-C1F1-448D-AFCA-E7C463FBA283@fastcrypt.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: pg@fastcrypt.com, javadesigner@yahoo.com
  Subject: Re: PreparedStatements, LIKE and the % operator
  In-Reply-To: <37697F6B-C1F1-448D-AFCA-E7C463FBA283@fastcrypt.com>
  References: <895911.8931.qm@web32005.mail.mud.yahoo.com> <37697F6B-C1F1-448D-AFCA-E7C463FBA283@fastcrypt.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox