setObject type for Interval objects

Поиск
Список
Период
Сортировка
Искать

setObject type for Interval objects

От:
David Goodenough <david.goodenough@btconnect.com>
Дата:
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.

So I guess I need the three parameter setObject, but I do not know what
type to pass to the third parameter.  I have googled, but to no avail (I 
obviously asked the wrong question).

David

Re: setObject type for Interval objects

От:
"Albe Laurenz" <all@adv.magwien.gv.at>
Дата:
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
FAQ