From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: PreparedStatements, LIKE and the % operator
Date: Sat, 03 Feb 2007 10:30:46 +0100
Message-ID: <eq1ko7$v73$1@sea.gmane.org> (raw)
In-Reply-To: <895911.8931.qm@web32005.mail.mud.yahoo.com>
References: <895911.8931.qm@web32005.mail.mud.yahoo.com>
j.random.programmer wrote on 03.02.2007 04:58:
> 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");
That should be:
String query = "select * from table_foo where bar like ?";
PreparedStatement ps = con.prepareStatement(query);
ps.setString(1, "%haha%");
Thomas
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: spam_eater@gmx.net
Subject: Re: PreparedStatements, LIKE and the % operator
In-Reply-To: <eq1ko7$v73$1@sea.gmane.org>
References: <895911.8931.qm@web32005.mail.mud.yahoo.com> <eq1ko7$v73$1@sea.gmane.org>
* 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