This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "preparedStatement.setDate and java.util.Date" Watch "preparedStatement.setDate and java.util.Date" New topic

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: 14074

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

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
I agree. Here's the link:
subject: preparedStatement.setDate and java.util.Date
Similar Threads
Using CacheRowset
Save date to the database
Date function
populating the databse
Enterprise application: handling date and time