|
|
||||||
|
#1
|
|
|
|
|
// DO NOT DO THIS!
// BUG: loses time of day preparedStatement.setDate(1, new java.sql.Date(date.getTime())); // DO THIS preparedStatement.setTimestamp(1, new java.sql.Timestamp(date.getTime())); // java.sql.Timestamp is not a date // MORE INFO GO TO http://www.thunderguy.com/semicolon/...t-a-real-date/ // GET BACK timestamp from DB // result set java.sql.Timestamp timestamp = resultSet.getTimestamp(1); java.util.Date d = new java.util.Date(timestamp.getTime() + timestamp.getNanos() / 1000000 or // Java 1.4+ java.util.Date d = resultSet.getTimestamp(1); |
|
|
|
#2
|
|
|
|
|
<anonieko> 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... :-) |
|
|
| Similar Threads | |
| Thread | Thread Starter |
| Convert SQL timestamp to Unix timestamp with timezone I've been running the following to convert SQL time into Unix time: select DATEDIFF(s, '19700101', end_date), end_date, start_date, event_sub_type, courseid from... |
Janet |
| why java timestamp format is different form php or normal unix format i'm wrting an application both in php and java i notice that java unixstamp is differenet from php any one know why ? java format 1203862011828 php and unix... |
islamelnaggar |
| java.sql.Timestamp and toString output according to [..]), Returns: a String object in yyyy-mm-dd hh:mm:ss.fffffffff format however, when I do import java.sql.Timestamp; ... Timestamp ts = new Timestamp(1000); |
Greg B |
| GIISR.DLL timestamp of module does not match timestamp of local mo Hello there, when debugging my ARM-based image, I get the warning: Loaded '{myDir}\GIISR.DLL', timestamp of module on device does not match timestamp of local module. I... |
Eike |
| java timestamp Ive search this newsgroup and google for a couple days now(off and on) and have not been able to figure this out. How do I get the current system time in the format:... |
netkev |
|
Privacy Policy | All times are GMT. The time now is 05:32 PM.
|
|
|