PreparedStatement error upon trying to set a '?' after interval keyword - Mailing list pgsql-jdbc

From javadesigner
Subject PreparedStatement error upon trying to set a '?' after interval keyword
Date
Msg-id 53E9144B.4010404@yahoo.com
Whole thread Raw
Responses Re: PreparedStatement error upon trying to set a '?' after interval keyword  (Sehrope Sarkuni <sehrope@jackdb.com>)
List pgsql-jdbc
Hi:

postgres: 9.3.4
driver: postgresql-9.3-1102.jdbc4.jar


I have the following query:

select
  count(*) from checkin
where
  pid = ? and checkin_time > current_date - interval '? days'

When I try to set the interval (parameter 2, second question mark):

ps.setLong("pid", 123);
ps.setInt("interval_days", 7);

I get the following error:

ERROR      org.postgresql.util.PSQLException: The column index is out of
range: 2, number of columns: 1
at
org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:56)

=====

I looked at the mailing list archives and whereas others have seen the
same issue, I am trying to understand the root cause of why the JDBC
driver throws an error here ? Should it just set the location of the
second question mark, with the specified data type (in this case in
integer) ? What's the point of throwing an error, why does the
preparedstatement care ? Its job is to simply replace question marks
with the specified data type, right ?

Best
--j
`


pgsql-jdbc by date:

Previous
From: Leonard Meyer
Date:
Subject: waitOnLOck on several threads when db connection lost
Next
From: Sehrope Sarkuni
Date:
Subject: Re: PreparedStatement error upon trying to set a '?' after interval keyword