KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using Java JDBC to write a date to SQL server 2008 and then read it back. The date that is read back is consistently two days earlier than the date that was actually written. I am inserting the row containing the Date field with a prepared statement. The date value is provided by: java.sql.Date todaysDate = new java.sql.Date(System.currentTimeMillis()) ; System.out.println(todaysDate.toString()) // -> 2012-07-02 ps.setDate(8, todaysDate); After writing the date to the DB, SQL server shows me the correct date if I run: select date from table_name where date!=null // ->2012-07-02 If I run the same query via JDBC then retrieve the date value from the resultset using java.sql.Date sqlDate = rs.getDate("date") ; sqlDate.toString() // ->2012-06-30 The inserted row is the only row in the table with a non-null date so this does not appear to be a case of reading the wrong record. I thought this would be a well known problem but the only reference I could find by a Google search for a "two days off" issue had no definitive answer. Any ideas? beeky (living in the past)
Tags (comma-separated)
Save Edits
Cancel