From: ml-tb <ml-tb@emagixx.de>
To: pgsql-jdbc@postgresql.org
Subject: Re: how to Escape single quotes with PreparedStatment
Date: Mon, 22 Aug 2011 09:46:37 +0200
Message-ID: <201108220946.37783.ml-tb@emagixx.de> (raw)
In-Reply-To: <1313988267050-4722152.post@n5.nabble.com>
References: <1313841345919-4718287.post@n5.nabble.com>
<201108211245.14465.mail@smogura.eu>
<1313988267050-4722152.post@n5.nabble.com>
Hi,
Am Montag, 22. August 2011 schrieb JavaNoobie:
> 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(%\"?\"%))";
It should be:
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(%?%))";
If you double quote the question mark, it would be an identifier (filed
name, tabel name ...). The question mark is the insert position for the
parameter. The prepared statement system escapes/expanded/... the
inserted value when necessary. The parameter number ist the count of a
question mark from left to right.
Bye Thomas
>
> 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.j
> ava:53) at
> org.postgresql.core.v3.SimpleParameterList.setStringParameter(SimpleP
> arameterList.java:118) at
> org.postgresql.jdbc2.AbstractJdbc2Statement.bindString(AbstractJdbc2S
> tatement.java:2184) at
> org.postgresql.jdbc2.AbstractJdbc2Statement.setString(AbstractJdbc2St
> atement.java:1303) at
> org.postgresql.jdbc2.AbstractJdbc2Statement.setString(AbstractJdbc2St
> atement.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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: ml-tb@emagixx.de
Subject: Re: how to Escape single quotes with PreparedStatment
In-Reply-To: <201108220946.37783.ml-tb@emagixx.de>
References: <1313841345919-4718287.post@n5.nabble.com> <201108211245.14465.mail@smogura.eu> <1313988267050-4722152.post@n5.nabble.com> <201108220946.37783.ml-tb@emagixx.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox