Re: how to Escape single quotes with PreparedStatment

From: JavaNoobie <vivek(dot)mv(at)enzentech(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: how to Escape single quotes with PreparedStatment
Date: 2011-08-22 09:56:49
Message-ID: 1314007009734-4722805.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi Andrew,
Thanks for the reply.
I'm, able to do that effectively . here's my corrected code snippet
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(?))OR (lower(?)='') AND
(lower(RESIDING_VILLAGE) LIKE (lower(?) OR (lower(?)='')) AND
(lower(WENEXA_ID) LIKE (lower(?))OR(lower(?)='')) LIMIT ? OFFSET ?";
stmt = con.prepareStatement(query);
stmt.setString(1,"%"+name+"%");
stmt.setString(2,"%"+name+"%");
stmt.setString(3,"%"+village+"%");
stmt.setString(4,"%"+village+"%");
stmt.setString(5,"%"+wenexaid+"%");
stmt.setString(6,"%"+wenexaid+"%");
stmt.setInt(7,pageLimit);
stmt.setInt(8,pageOffset);
rs= stmt.executeQuery();
However , it throws near the LIMIT clause. As below:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "LIMIT"
Position: 302
at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)

Any idea about this one?

--
View this message in context: http://postgresql.1045698.n5.nabble.com/how-to-Escape-single-quotes-with-PreparedStatment-tp4718287p4722805.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Chris Wareham 2011-08-22 10:04:43 Re: how to Escape single quotes with PreparedStatment
Previous Message Andrew Hastie 2011-08-22 09:47:29 Re: how to Escape single quotes with PreparedStatment