Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id F00529FA16B for ; Fri, 2 Feb 2007 23:58:47 -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 35407-07 for ; Fri, 2 Feb 2007 23:58:32 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from web32005.mail.mud.yahoo.com (web32005.mail.mud.yahoo.com [68.142.207.102]) by postgresql.org (Postfix) with SMTP id 7EAB99FA0C0 for ; Fri, 2 Feb 2007 23:58:44 -0400 (AST) Received: (qmail 9048 invoked by uid 60001); 3 Feb 2007 03:58:42 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=iA+Bft8WffioY2Rp1vH0xNNYqrbtCkZxCnHcLeO91wstbATnhr9tDiNLLAOHlOSwqhLm+BS43xp4p2bo93pZmgLryF5UPc5R6Wq4C4DA2psS/83XMGSRjELi11q5y9ECwfH2K0SuK46K+RXBpoVA6cfwt6Hrb2qCjy9u5hcFOtI=; X-YMail-OSG: T3qT1g4VM1mqgaq2OuSUf6iQxhiDHz4Qhdt5w8BT2A3xuMZCpeuOdug8sIxNUXlu.fg7ipFO8EQOfOqSrH9hBvnNwown62hYWVhCk7IkQWdNaufpnpXHEf2vlWDGi8RugJcXR.rLJKND5LM- Received: from [165.123.243.168] by web32005.mail.mud.yahoo.com via HTTP; Fri, 02 Feb 2007 19:58:42 PST Date: Fri, 2 Feb 2007 19:58:42 -0800 (PST) From: "j.random.programmer" Subject: PreparedStatements, LIKE and the % operator To: pgsql-jdbc@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <895911.8931.qm@web32005.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.356 tagged_above=0 required=5 tests=BAYES_50, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS X-Spam-Level: *** X-Archive-Number: 200702/22 X-Sequence-Number: 16578 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