From: Kris Jurka <books@ejurka.com>
To: Peter <peter@greatnowhere.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: JDBC problem with dates and ANYELEMENT type
Date: Fri, 24 Apr 2009 13:20:43 -0700
Message-ID: <49F21F1B.7010803@ejurka.com> (raw)
In-Reply-To: <01e001c9c4b8$e28c93a0$a7a5bae0$@com>
References: <00e701c9c3eb$625d43a0$2717cae0$@com>
<Pine.BSO.4.64.0904232234430.16180@leary.csoft.net>
<01e001c9c4b8$e28c93a0$a7a5bae0$@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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: books@ejurka.com, peter@greatnowhere.com
Subject: Re: JDBC problem with dates and ANYELEMENT type
In-Reply-To: <49F21F1B.7010803@ejurka.com>
References: <00e701c9c3eb$625d43a0$2717cae0$@com> <Pine.BSO.4.64.0904232234430.16180@leary.csoft.net> <01e001c9c4b8$e28c93a0$a7a5bae0$@com> <49F21F1B.7010803@ejurka.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox