Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id F16279FB1C4 for ; Sat, 3 Feb 2007 05:31:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 25489-09 for ; Sat, 3 Feb 2007 05:31:08 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id 3DA869FA176 for ; Sat, 3 Feb 2007 05:31:10 -0400 (AST) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HDHEZ-0004hm-04 for pgsql-jdbc@postgresql.org; Sat, 03 Feb 2007 10:30:59 +0100 Received: from ppp-82-135-82-52.dynamic.mnet-online.de ([82.135.82.52]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 03 Feb 2007 10:30:58 +0100 Received: from spam_eater by ppp-82-135-82-52.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 03 Feb 2007 10:30:58 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: PreparedStatements, LIKE and the % operator Date: Sat, 03 Feb 2007 10:30:46 +0100 Lines: 21 Message-ID: References: <895911.8931.qm@web32005.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: ppp-82-135-82-52.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.9) Gecko/20061207 Thunderbird/1.5.0.9 Mnenhy/0.7.4.0 In-Reply-To: <895911.8931.qm@web32005.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/25 X-Sequence-Number: 16581 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