Jump to content



Photo

Dates changing by 2 days - Java+SQL Server

java sql jsf database

  • Please log in to reply
3 replies to this topic

#1 Lord Method Man

Lord Method Man

    Banned

  • Tech Issues Solved: 1
  • Joined: 18-September 12

Posted 19 September 2012 - 14:27

We're working on a web-based application running JSF on a JBoss server. It deals with a lot of dates which are being problematic.

In the Java beans the dates are handled as Date objects and are being stored in a database. Whenever a Date is stored in the database it is changed to -2 days from what it was in Java. (I.E. If the Date object in the bean is May 8, 2012 the Date in the database will be May 6, 2012; if the Java Date is Jan 1, 2010 the database date is Dec 30, 2009).

When the Dates are retrieved from the database they remain off by 2 days. Obviously there is a conflict between how Java and SQL handle date objects and we would like to find a good fix for it.

Here are a couple work-arounds we are considering should a "proper" solution not exist:
- Add 2 days to each Java date before calling the stored procedure
- Convert the Java date to a string before storing it and have SQL convert the string to a date

Has anyone encountered this before or could explain why it is doing this, and if so is there a correct solution for it?


#2 Kami-

Kami-

    ♫ d(-_-)b ♫

  • Tech Issues Solved: 2
  • Joined: 28-July 08
  • Location: SandBox

Posted 19 September 2012 - 19:27

Care to post some sample code?

#3 OP Lord Method Man

Lord Method Man

    Banned

  • Tech Issues Solved: 1
  • Joined: 18-September 12

Posted 20 September 2012 - 12:59

Supposedly it's fixed now. I was told it had to do with the libraries being used on the JBoss server. I wasn't given specifics, someone else got it working.

#4 Kami-

Kami-

    ♫ d(-_-)b ♫

  • Tech Issues Solved: 2
  • Joined: 28-July 08
  • Location: SandBox

Posted 21 September 2012 - 00:35

Ok, glad it's working.