Re: Timestamp vs. Java Date/Timestamp

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: Timestamp vs. Java Date/Timestamp
Дата
Msg-id kfge0s$l8m$1@ger.gmane.org
обсуждение исходный текст
Ответ на Re: Timestamp vs. Java Date/Timestamp  (Andreas Reichel <andreas@manticore-projects.com>)
Список pgsql-jdbc
Andreas Reichel, 13.02.2013 06:37:
> On the same time java.sql.Date and java.util.Date support time
> information and in fact you can handover a java.sql.Date parameter to a
> Timestamp field.

But due to the removing of the time part this will *not* work.

> This is the part when I get confused: the timestamp field holds time
> information, the java.sql.Date parameter holds time information -- still
> it is cut off in the middle.

Yes, that's per documentation.

http://docs.oracle.com/javase/6/docs/api/java/sql/Date.html

"To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date
instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero [...]"

Note the part about "setting ... to zero"

So as soon as you create a java.sql.Date you lose the time information.

If you want to be JDBC compliant there are only two simple things to remember:

* use java.sql.Date together with setDate()/getDate() for date columns
* use java.sql.Timestamp together with setTimestamp()/getTimestamp() for timestamp columns

This works across all DBMS that I have worked with
(Oracle is a bit special but in general you should simply treat their DATE as timestamp)

The only problem are columns with timezones as none of the Java classes can deal with that.

Thomas


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

Предыдущее
От: Andreas Reichel
Дата:
Сообщение: Re: Timestamp vs. Java Date/Timestamp
Следующее
От: dmp
Дата:
Сообщение: Re: Timestamp vs. Java Date/Timestamp