Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8219549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:12:22+00:00 2026-06-07T13:12:22+00:00

I am using Java JDBC to write a date to SQL server 2008 and

  • 0

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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:12:23+00:00Added an answer on June 7, 2026 at 1:12 pm

    Faulty JDBC Driver

    It turns out the problem was the MS JDBC driver. I tried every possible combination of date types and date conversions and nothing worked. After a great deal of searching (should have done that first!) I saw a comment on an older SO entry that implied the problem was the version 3 JDBC driver from Microsoft. I got the latest driver, version 4.something, and the problem went away.

    Thanks to all that tried to help. Special thanks to you Mike for taking the time to post a solution.

    -=beeky

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using playframework with a legacy SQL Server 2008 database that has data
I have a Java web app running on Tomcat 7 that is using JDBC
I am trying to connect to a MySQL Server using JDBC tool in java
I'm new to java and trying to write a simple program using JDBC. It
I want to write a transaction using jdbc in java . I have tried
I have a stand-alone java application that makes some database read/write business on a
I'm trying write a test for a method that returns a java.sql.Connection to connect
I write Java program using JDBC (mysql database). When I violate mysql integrity (f.e.
I am using jdbc to write a java desktop application, and this application will
I have a java plugin to an application that I'm using (I didn't write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.