aspose file tools
The moose likes JDBC and Relational Databases and the fly likes preparedStatement.setDate and java.util.Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "preparedStatement.setDate and java.util.Date" Watch "preparedStatement.setDate and java.util.Date" New topic
Author

preparedStatement.setDate and java.util.Date

hani Ibrahim
Ranch Hand

Joined: Sep 06, 2006
Posts: 182
i tried to setDate for preparedStatement and piyt in it java.util.Date object but it is falied at compile time,if make cast to it at runtime exception cast exception.
how to send java.util.Date to DB please
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

As can be seen from the javadoc api, PreparedStatement.setDate() is accepting java.sql.Date object..not java.util.Date.
hani Ibrahim
Ranch Hand

Joined: Sep 06, 2006
Posts: 182
i know that because of that i asked how to send Date from java to Database?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14487
    
  23

Convert your java.util.Date object to a java.sql.Date object:



Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: preparedStatement.setDate and java.util.Date