• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java.util.Date binding issue with PreparedStatement

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes , i have upgraded jdbc driver to Java 8
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using ATG RQL for updating my DB, which will internally convert to PreparedStatement.
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an issue with ojdbc7.jar
 
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic