Re: Java Timestamp in SQL




<anonieko@xxxxxxxxxxx> wrote...

> // DO NOT DO THIS!
> // BUG: loses time of day
> preparedStatement.setDate(1, new java.sql.Date(date.getTime()));

It's no bug at all, though it's not *convenient* for us Java developers.

Instead it's quite logical, as java.sql.* pretty much conforms to...

SQL!

Those databases that really conform to "standard" SQL *doesn't* have any
time information in their DATE-fields (hence a java.sql.Date), instead they
have it in TIME-fields (note there is also a java.sql.Time!).

And there's also the datatype TIMESTAMP in the standard form of SQL, to have
a combination of date and time (hence the java.sql.Timestamp!)...

Unfortunately there's plenty of db:s that *doesn't* conform to standard SQL,
such as Oracle, MS Access/Jet, SQL Server, etc...

For the fields that includes both date and time in those databases, the
*closest* thing to represent it is java.sql.Timestamp.

No bug...

// Bjorn A

P.S. No, I'm not shouting, it's a common practice
to use only upper-case letters in SQL... :-)



.