Re: Could not determine data type of parameter $1

From: Kris Jurka <books(at)ejurka(dot)com>
To: Vincent Risi <vince(at)bbd(dot)co(dot)za>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Could not determine data type of parameter $1
Date: 2006-08-30 02:56:28
Message-ID: Pine.BSO.4.63.0608292151450.28706@leary2.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2006-08-30 03:42:38 Re: JDK5 and TimeTest
Previous Message Kris Jurka 2006-08-30 02:47:08 Re: error: ResultSet.updateObject(timestamp in POSTGRES,