Re: Could not determine data type of parameter $1 - Mailing list pgsql-jdbc

From Kris Jurka
Subject Re: Could not determine data type of parameter $1
Date
Msg-id Pine.BSO.4.63.0608292151450.28706@leary2.csoft.net
Whole thread Raw
In response to Could not determine data type of parameter $1  (Vincent Risi <vince@bbd.co.za>)
Responses Re: Could not determine data type of parameter $1  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-jdbc

On Fri, 25 Aug 2006, Vincent Risi wrote:

> ////////////////////////////
>
> Using the version of the jbdc drive (postgresql-8.1dev-400.jdbc3.jar)
> instead of (postgresql-8.1-407.jdbc3.jar) the code below works. I would
> like to know if the code is valid or if the driver has a problem. It
> fails at
>
> [
>   PreparedStatement ps = conn.prepareStatement("SELECT ?");
>   ps.setTimestamp(1, new Timestamp(0));
>   ResultSet rs = ps.executeQuery();
> ]
>

When given a timestamp parameter the jdbc driver does not know if it is
going to be used a timestamp with time zone or a timestamp without time
zone.  The driver passes it to the server as an unknown data type letting
the server figure out what to do with it.  Usually you'll have
timestampcol = ? or you're inserting into a timestamp field so the server
can easily determine the true datatype the parameter is being used at.  In
this case since it's just being sent back to the user the server cannot
determine the type and bails out.  You need to help it along with a cast:
"SELECT ?::timestamptz".

Kris Jurka


pgsql-jdbc by date:

Previous
From: Kris Jurka
Date:
Subject: Re: error: ResultSet.updateObject(timestamp in POSTGRES,
Next
From: Kris Jurka
Date:
Subject: Re: JDK5 and TimeTest