• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java.util.Date binding issue with PreparedStatement  RSS feed

 
rahul r nair
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am migrating my application from Java 6 to Java 8 and observing the following issue in java 8

In java6 iam using java.util.date and while executing the below statemet

PreparedStatement.setDate(new Date())  only date will be inserted in my oracle DB with as 09-02-2017 00:00:00

but in java 8 the same statement is updating my DB with 09-02-2017 12:12:34 .

Due to the time stamp value i am having problem with my Application.
Please let me know how this can be corrected.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36660
475
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds like a bug. setDate() is only supposed to set the date. Are you using a different JDBC driver now that you've upgraded to Java 8?

A workaround would of course be to create a Calendar object and zero out the time.
 
rahul r nair
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , i have upgraded jdbc driver to Java 8
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36660
475
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can run Java 8 code with an older driver. I recommend trying with the older driver (but running on Java 8). If it works as expected, you found a bug/change of behavior in the driver.
 
Paul Clapham
Sheriff
Posts: 22215
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rahul r nair wrote:In java6 iam using java.util.date and while executing the below statemet

PreparedStatement.setDate(new Date())


I don't understand that. The setDate() method requires a java.sql.Date object, and since java.util.Date isn't a subclass of java.sql.Date, that code should not compile.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36660
475
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point. I thought he was using a java.sql import.
 
rahul r nair
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using ATG RQL for updating my DB, which will internally convert to PreparedStatement.
 
Paul Clapham
Sheriff
Posts: 22215
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha! So there's another piece of code which could be the reason for your complaint!
 
rahul r nair
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an issue with ojdbc7.jar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!