Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 076239FB1BF for ; Sat, 3 Feb 2007 00:37:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 85992-05 for ; Sat, 3 Feb 2007 00:37:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by postgresql.org (Postfix) with SMTP id 581C89FB28F for ; Sat, 3 Feb 2007 00:37:24 -0400 (AST) Received: (qmail 678 invoked from network); 3 Feb 2007 04:37:23 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.14?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 3 Feb 2007 04:37:23 -0000 In-Reply-To: <895911.8931.qm@web32005.mail.mud.yahoo.com> References: <895911.8931.qm@web32005.mail.mud.yahoo.com> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <37697F6B-C1F1-448D-AFCA-E7C463FBA283@fastcrypt.com> Cc: pgsql-jdbc@postgresql.org Content-Transfer-Encoding: 7bit From: Dave Cramer Subject: Re: PreparedStatements, LIKE and the % operator Date: Fri, 2 Feb 2007 23:37:23 -0500 To: j.random.programmer X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/23 X-Sequence-Number: 16579 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 >