• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Save date to the database

 
Justin Howard
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic