I am developing a web application based on JSF technology. I use Eclipse as the IDE and using Apache Derby as a database.
When getting user input, I have one of the fields as a date field, ie, Date of Birth. But when I update the database table, I get error report.
Date Of Birth:
<h:inputText value="#{employeeBean.dob}">
<f:convertDateTime type="date" pattern="yyyy-mm-dd"/>
</h:inputText>
Since the derby database accepts date in the format yyyy-mm-dd, I give input in the same way and have also used the same format.
This is the error I get.
Exception while setting value for expression : #{employeeBean.dob} of component with
path : {Component-Path : [Class:javax.faces.component.UIViewRoot,ViewId: /homepage.jsp]
[Class: javax.faces.component.html.HtmlForm,Id: j_id_jsp_996426310_1]
[Class: javax.faces.component.html.HtmlInputText,Id: j_id_jsp_996426310_6]}
Caused by:
java.lang.IllegalArgumentException - Cannot convert 1/8/87 5:39 AM of type class
java.util.Date to class java.sql.Date
Some one help me with this.
Since JSF uses java.util.Date
and derby perhaps expects java.sql.Date
, you have to do something in order to acoomodate this gap:
java.util.Date
if doing only the above doesn't work, convert between the two before saving. This can be done with the following constructor (Note that I don't know how you are going to persist the object to the database, so I'm guessing)
java.sql.Date date = new java.sql.Date(jsfProvidedDate.getTime());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.