Re: how to Escape single quotes with PreparedStatment - Mailing list pgsql-jdbc

From JavaNoobie
Subject Re: how to Escape single quotes with PreparedStatment
Date
Msg-id 1313988267050-4722152.post@n5.nabble.com
Whole thread Raw
In response to Re: how to Escape single quotes with PreparedStatment  (Radosław Smogura <mail@smogura.eu>)
Responses Re: how to Escape single quotes with PreparedStatment
List pgsql-jdbc
Hi All ,
Thank you all for your replies. The prepared statement block that I try to
execute , after adding parameters is as follows ,(I've simplified the query
so that I can understand the concept)

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(%\"?\"%))";

                stmt = con.prepareStatement(query);
                stmt.setString(1, name);
                rs= stmt.executeQuery();
However upon executing the block, I get an error as follows
org.postgresql.util.PSQLException: The column index is out of range: 1,
number of columns: 0.
    at
org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:53)
    at
org.postgresql.core.v3.SimpleParameterList.setStringParameter(SimpleParameterList.java:118)
    at
org.postgresql.jdbc2.AbstractJdbc2Statement.bindString(AbstractJdbc2Statement.java:2184)
    at
org.postgresql.jdbc2.AbstractJdbc2Statement.setString(AbstractJdbc2Statement.java:1303)
    at
org.postgresql.jdbc2.AbstractJdbc2Statement.setString(AbstractJdbc2Statement.java:1289)
    at com.enzen.cis.dao.DAOConsumerSearch.getcList(DAOConsumerSearch.java:5

Any idea why this could be happening?
Thank you.

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

pgsql-jdbc by date:

Previous
From: Radosław Smogura
Date:
Subject: Re: how to Escape single quotes with PreparedStatment
Next
From: "ml-tb"
Date:
Subject: Re: how to Escape single quotes with PreparedStatment