Re: PreparedStatement error for date parameter with overlaps

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Simon Mitchell <simon(at)jseb(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PreparedStatement error for date parameter with overlaps
Date: 2011-05-31 03:32:02
Message-ID: BANLkTimUcH1JCKavKmsjf-4uEQ09=jZnXg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 31 May 2011 15:12, Simon Mitchell <simon(at)jseb(dot)com> wrote:

> The strange thing is the doing a toString() before executeQuery() prints out
> the sql as per the postgres example, I can cut and past it into psql and it
> runs fine.

PreparedStatement.toString() isn't guaranteed to give you the query as
executed (or even a syntactically correct query!), it just substitutes
parameter values into the query string to give you something that
might be more useful for debugging than the default Object.toString()
implementation.

If you wanted to get the equivalent query in psql, you should take
your query string and replace ? with $1, $2, etc, then use
PREPARE/EXECUTE. That's much closer to how the JDBC driver actually
executes queries; the driver does *not* just substitute values into
the query string.

Oliver

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Craig Ringer 2011-05-31 05:27:48 Re: PreparedStatement error for date parameter with overlaps
Previous Message Simon Mitchell 2011-05-31 03:12:12 Re: PreparedStatement error for date parameter with overlaps