Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 5613FB5DBBF for ; Sat, 20 Aug 2011 12:14:12 -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 68086-08 for ; Sat, 20 Aug 2011 15:14:05 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outbound.vnet-inc.com (outbound.vnet-inc.com [216.146.104.103]) by mail.postgresql.org (Postfix) with ESMTP id 7F44FB5D803 for ; Sat, 20 Aug 2011 12:14:05 -0300 (ADT) Received: from [192.168.157.132] (unknown [76.75.27.41]) by outbound.vnet-inc.com (Postfix) with ESMTP id 8435B5807 for ; Sat, 20 Aug 2011 09:14:04 -0600 (MDT) Message-ID: <4E4FCE49.2000605@ttc-cmc.net> Date: Sat, 20 Aug 2011 09:10:01 -0600 From: dmp User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.13) Gecko/20100914 SeaMonkey/2.0.8 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> In-Reply-To: <1313841345919-4718287.post@n5.nabble.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201108/43 X-Sequence-Number: 22075 JavaNoobie wrote: > Hi All, > I'm trying to write a preparedstatement query as below. > > 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('%"+name+"%'))OR > (lower('" + name + "')='')) AND (lower(RESIDING_VILLAGE) LIKE > (lower('%"+village+"%')) OR (lower('" + village + "')='')) AND > (lower(WENEXA_ID) LIKE (lower('%"+wenexaid+"%'))OR(lower( '" + wenexaid + > "')='')) LIMIT '"+pageLimit+"'OFFSET '"+pageOffset+"'"; > > stmt = con.prepareStatement(query); > rs= stmt.executeQuery(); > > However , the query fails with postgresql when a double quote is passed into > it.I was under the impression that Prepared statement would take care of the > same . But can anyone explain why I'm getting the error? > Thank you. Perhaps to get a better idea of what exactly the query string is that is being executed you could: System.out.println(query); stmt = con.prepareStatement(query); rs= stmt.executeQuery(); danap.