Re: JDBC problem with dates and ANYELEMENT type

Поиск
Список
Период
Сортировка
Искать
От
Kris Jurka
Тема
Re: JDBC problem with dates and ANYELEMENT type
Дата
Msg-id
49F21F1B.7010803@ejurka.com
Ответ на
Список
Дерево обсуждения
JDBC problem with dates and ANYELEMENT type "Peter" <peter@greatnowhere.com>
Re: JDBC problem with dates and ANYELEMENT type Kris Jurka <books@ejurka.com>
Re: JDBC problem with dates and ANYELEMENT type "Peter" <peter@greatnowhere.com>
Re: JDBC problem with dates and ANYELEMENT type John Lister <john.lister-ps@kickstone.com>
Re: JDBC problem with dates and ANYELEMENT type Kris Jurka <books@ejurka.com>
Re: JDBC problem with dates and ANYELEMENT type "Peter" <peter@greatnowhere.com>
Peter wrote:
>>> Any suggestions how to work around this so we can still use
>>> ANYELEMENT and pass in DATE?
> 
>> You can put a cast into the query itself "SELECT ?::date".
> 
> Nah... that's no good. The same query string is used for many
> different types in my app - such approach would require me to parse
> the SQL string and append cast to date when argument is
> java.sql.Date.  I'll leave this as last-ditch approach.

The other way of providing explicit type information is to create an 
object that extends PGobject.  Something like:

import java.util.Date;
import java.text.SimpleDateFormat;
import org.postgresql.util.PGobject;

class MyDateWrapper extends PGobject {

     public MyDateWrapper(java.util.Date d) {
         setType("date");
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
         setValue(df.format(d));
     }
}

Then call PreparedStatement.setObject with an instance of MyDateWrapper.

Kris Jurka

В списке pgsql-jdbc по дате отправления
От: Thomas Kellerer
Дата:
От: Kris Jurka
Дата:
FAQ