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 Beginning Java and the fly likes Save date to the database 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 » Java » Beginning Java
Bookmark "Save date to the database" Watch "Save date to the database" New topic
Author

Save date to the database

Justin Howard
Ranch Hand

Joined: Feb 19, 2009
Posts: 162
Hi All,

I am trying to save the date from the form.



Then trying to save the sqlDate to the database.
But I get this eception
Exception: java.util.Date cannot be cast to java.sql.Date

What is the correct way to do it?

Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Right. So you can't cast. Therefore you need to create a new java.sql.Date object. So, the first place to go is the API documentation, to see whether there are any suitable constructors for java.sql.Date. Give that a try. Come back here if you can't figure out how to use any of the constructors.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Check your imports. Which Date are you importing, java.util.Date or java.sql.Date? Because if you use the right import (java.util), your code seems to be just fine.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Save date to the database
 
Similar Threads
problem insering date value in database
preparedStatement.setDate and java.util.Date
Just realise something interesting about Date in Java and SQL
date problem
Updating Date