|
|
||||||
|
#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 | |
| 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... |
|
| 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); |
|
| 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... |
|
| 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:... |
|
| Convert unix timestamp to postgres timestamp I'm writting a little calendar script and I need to insert a pair of start and end timestamps into a postgres database table. These are in unix format (seconds since 1st Jan... |
|
|
All times are GMT. The time now is 09:53 PM. | Privacy Policy
|