using Date and setObject()

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

using Date and setObject()

От:
Leandro Rodrigo Saad Cruz <leandro@ibnetwork.com.br>
Дата:
Hi all, I'm working an a persistence layer API above JDBC
that uses setObject() in prepare statements. the problem is : 
I get a ClassCastException when using setObject(java.util.Date).
Can I use setObject(java.util.Date) or I **must** use
setDate(java.util.Date) ??

-- 
Leandro Rodrigo Saad Cruz
IT - Inter Business Tecnologia e Servicos (IB)
http://www.ibnetwork.com.br

Re: using Date and setObject()

От:
Thomas O'Dowd <tom@nooper.com>
Дата:
Never tried it but what about using setObject(java.sql.Date)
                                                   ^^^

The big difference between the objects of course is that the 
java.sql.Date only holds the date part and not the time part.

Tom.

On Wed, Apr 17, 2002 at 02:53:43PM -0300, Leandro Rodrigo Saad Cruz wrote:
> Hi all, I'm working an a persistence layer API above JDBC
> that uses setObject() in prepare statements. the problem is : 
> I get a ClassCastException when using setObject(java.util.Date).
> Can I use setObject(java.util.Date) or I **must** use
> setDate(java.util.Date) ??
> 
> -- 
> Leandro Rodrigo Saad Cruz
> IT - Inter Business Tecnologia e Servicos (IB)
> http://www.ibnetwork.com.br
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
> http://www.postgresql.org/users-lounge/docs/faq.html

-- 
Thomas O'Dowd. - Nooping - http://nooper.com
tom@nooper.com - Testing - http://nooper.co.jp/labs

Re: using Date and setObject()

От:
"Joe Shevland" <jshevland@j-elite.com>
Дата:
The big difference is of course, is that the java.sql.Date is "A thin wrapper around a millisecond value that allows JDBC to identify this as a SQL DATE (JDK1.3.1 doco)" - it subclasses java.util.Date so certainly holds time ;)

In relation before that, java.util.Date holds a specific instance in time - without timezones coming into play - in reality the amount of seconds since Unix birth or 1970 or whatever it is. I'm not sure about the JDBC driver and backend interaction, but I'd be using a GregorianCalendar or Calendar instance instead, which is more suitable for manipulating dates and times. I'm not sure if the setObject() method caters for this though.

Cheers,
Joe

> Never tried it but what about using setObject(java.sql.Date)
>                                                    ^^^
> 
> The big difference between the objects of course is that the 
> java.sql.Date only holds the date part and not the time part.
> 
> Tom.
> 
> On Wed, Apr 17, 2002 at 02:53:43PM -0300, Leandro Rodrigo Saad Cruz wrote:
> > Hi all, I'm working an a persistence layer API above JDBC
> > that uses setObject() in prepare statements. the problem is : 
> > I get a ClassCastException when using setObject(java.util.Date).
> > Can I use setObject(java.util.Date) or I **must** use
> > setDate(java.util.Date) ??
> > 
> > -- 
> > Leandro Rodrigo Saad Cruz
> > IT - Inter Business Tecnologia e Servicos (IB)
> > http://www.ibnetwork.com.br

FAQ