Re: setObject type for Interval objects

From: "Albe Laurenz" <all(at)adv(dot)magwien(dot)gv(dot)at>
To: "David Goodenough *EXTERN*" <david(dot)goodenough(at)btconnect(dot)com>, <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: setObject type for Interval objects
Date: 2007-06-28 13:00:28
Message-ID: AFCCBB403D7E7A4581E48F20AF3E5DB20395C520@EXADV1.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

David Goodenough wrote:
>
> I have an SQL SELECT which contains an expressions of the form:-
>
> WHERE created < CURRENT_TIMESTAMP - ?
>
> where created is a TIMESTAMP field. As a parameter I want to pass
> an interval, so I used:-
>
> PGInterval interval = new PGInterval( intervalPeriod);
> stmt.setObject( 1, interval);
>
> but Postgresql objects with:-
>
> org.postgresql.util.PSQLException: Can't infer the SQL type
> to use for an instance of org.postgresql.util.PGInterval.
> Use setObject() with an explicit Types value to specify
> the type to use.

Strange - here (postgresql-8.2-505.jdbc3.jar with JDK 1.5.0_12-b04)
the following code runs fine:

Connection conn = DriverManager.getConnection();
PreparedStatement stmt = conn.prepareStatement(
"SELECT current_timestamp - ?");
stmt.setObject(1, new PGInterval("2 days"));
ResultSet rs = stmt.executeQuery();

Yours,
Laurenz Albe

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Loredana Curugiu 2007-07-02 08:23:58 Replace usage of a table in query with its array values
Previous Message David Goodenough 2007-06-28 09:58:17 setObject type for Interval objects