Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 6D3A5B5DBDA for ; Mon, 22 Aug 2011 06:46:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 00992-06 for ; Mon, 22 Aug 2011 09:45:54 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from cpanelsmarthost2.zen.co.uk (cpanelsmarthost2.zen.co.uk [82.71.204.226]) by mail.postgresql.org (Postfix) with ESMTP id 9EF18B5D803 for ; Mon, 22 Aug 2011 06:45:54 -0300 (ADT) Received: from [88.98.24.71] (helo=shcp03.hosting.zen.net.uk) by cpanelsmarthost2.zen.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1QvR4m-0003G9-7a for pgsql-jdbc@postgresql.org; Mon, 22 Aug 2011 09:45:52 +0000 Received: from [212.135.39.5] (helo=[62.185.32.161]) by shcp03.hosting.zen.net.uk with esmtpa (Exim 4.69) (envelope-from ) id 1QvR4j-0007Nz-9y for pgsql-jdbc@postgresql.org; Mon, 22 Aug 2011 10:45:45 +0100 Message-ID: <4E5225B1.1030506@ahastie.net> Date: Mon, 22 Aug 2011 10:47:29 +0100 From: Andrew Hastie User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 Thunderbird/3.1.11 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: how to Escape single quotes with PreparedStatment References: <1313841345919-4718287.post@n5.nabble.com> <201108211245.14465.mail@smogura.eu> <1313988267050-4722152.post@n5.nabble.com> <201108220946.37783.ml-tb@emagixx.de> <1314000874022-4722528.post@n5.nabble.com> In-Reply-To: <1314000874022-4722528.post@n5.nabble.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - shcp03.hosting.zen.net.uk X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - ahastie.net X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.778 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201108/50 X-Sequence-Number: 22082 I think you're defining the "?" parameter incorrectly for the PreparedStatement. Try this instead:- String query="SELECT count(*) over () as ROWCOUNT, CONSUMER_ID,WENEXA_ID,CONSUMER_NAME,CONTACT_NO,residing_village from db_consumer WHERE lower(CONSUMER_NAME) LIKE (lower(?))"; query.setString(1,"%Fred%"); Where "Fred" is the string you're searching for. You cannot use the ? token to substitute part of data value, only a whole value. As you are parameterizing the "pattern" argument to the LIKE expression which is a String argument, you must pass the complete pattern as a String parameter. Hope this helps, Andrew On 22/08/11 09:14, JavaNoobie wrote: > Hi, > I tried that example but it threw an error as follows. > org.postgresql.util.PSQLException: ERROR: syntax error at or near "%" > Position: 158 > at > org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102) > at > org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835) > > Why could this be happening? > > -- > View this message in context: http://postgresql.1045698.n5.nabble.com/how-to-Escape-single-quotes-with-PreparedStatment-tp4718287p4722528.html > Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com. >