Re: setObject type for Interval objects

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: setObject type for Interval objects
Дата
Msg-id AFCCBB403D7E7A4581E48F20AF3E5DB20395C520@EXADV1.host.magwien.gv.at
обсуждение исходный текст
Ответ на setObject type for Interval objects  (David Goodenough <david.goodenough@btconnect.com>)
Список 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

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: David Goodenough
Дата:
Сообщение: setObject type for Interval objects
Следующее
От: "Loredana Curugiu"
Дата:
Сообщение: Replace usage of a table in query with its array values