• 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

Cannot convert 4/21/16 12:00 AM of type class java.util.Date to class java.sql.Date

 
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good morning

I have this error (/UI/AddTask.jsp(34,5) '#{taskBean.startDate}' Cannot convert 4/21/16 12:00 AM of type class java.util.Date to class java.sql.Date )
and I'm trying to solve it by convert the data but it dose not work with me.

i have DB that save this date from the JSF and the TaskBean, can any one please see what is the problem!

TaskBean:




JSF:



Thank you.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java.util.Date and java.sql.Date are very similar classes, but they do not directly convert.

The RichFaces Calendar control requires a java.util.Date, just as radiobuttons require booleans.

It is important to remember that the JSF backing bean is a GUI Model object and not a persistence Model object. While sometimes the same object can be used in both roles, that would not be the case for dates and booleans if the persistence model isn't using java util.Date or java.lang.Boolean/boolean.

You could probably use a customer Converter to translate the backing bean property for your dates, but in your particular case, it's probably just as easy to do it this way:


And change the import on your backing bean from java.sql.Date to java.util.Date
 
reply
    Bookmark Topic Watch Topic
  • New Topic