Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 91055634B90 for ; Fri, 24 Apr 2009 17:20:53 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 34059-04-2 for ; Fri, 24 Apr 2009 17:20:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail63.csoft.net (mail63.csoft.net [205.205.214.4]) by mail.postgresql.org (Postfix) with ESMTP id D92F4634D38 for ; Fri, 24 Apr 2009 17:20:47 -0300 (ADT) Received: from [192.168.1.141] (adsl-71-128-101-241.dsl.irvnca.pacbell.net [71.128.101.241]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail63.csoft.net (Postfix) with ESMTP id E76CF2841F; Fri, 24 Apr 2009 16:20:44 -0400 (EDT) Message-ID: <49F21F1B.7010803@ejurka.com> Date: Fri, 24 Apr 2009 13:20:43 -0700 From: Kris Jurka User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: Peter CC: pgsql-jdbc@postgresql.org Subject: Re: JDBC problem with dates and ANYELEMENT type References: <00e701c9c3eb$625d43a0$2717cae0$@com> <01e001c9c4b8$e28c93a0$a7a5bae0$@com> In-Reply-To: <01e001c9c4b8$e28c93a0$a7a5bae0$@com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/88 X-Sequence-Number: 19535 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