Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id F203BB5DC05 for ; Sat, 20 Aug 2011 09:15:51 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 84360-04-6 for ; Sat, 20 Aug 2011 12:15:45 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sam.nabble.com (sam.nabble.com [216.139.236.26]) by mail.postgresql.org (Postfix) with ESMTP id 6B2EBB5DBF8 for ; Sat, 20 Aug 2011 09:15:45 -0300 (ADT) Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1Quk9R-0006jz-U0 for pgsql-jdbc@postgresql.org; Sat, 20 Aug 2011 04:55:45 -0700 Date: Sat, 20 Aug 2011 04:55:45 -0700 (PDT) From: JavaNoobie To: pgsql-jdbc@postgresql.org Message-ID: <1313841345919-4718287.post@n5.nabble.com> Subject: how to Escape single quotes with PreparedStatment MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201108/42 X-Sequence-Number: 22074 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. -- View this message in context: http://postgresql.1045698.n5.nabble.com/how-to-Escape-single-quotes-with-PreparedStatment-tp4718287p4718287.html Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.