Reputation: 79
I am facing difficulties while trying to insert a date variable into a database table. My variable is called:
Date date4;
The date4 variable value is read from a textbox which has a calendar picker. For inserting in a date column, I am setting the field type to date:
preparedstmt.setDate(4,date4);
However, I got the below message after submitting the form:
javax.faces.component.UpdateModelException: java.lang.IllegalArgumentException: Cannot convert 4/1/15 12:00 AM of type class java.util.Date to class java.sql.Date
Also, is there a way to insert the field in the format of date ("dd-MON-YYYY")?
Upvotes: 1
Views: 173
Reputation: 34424
Convert util date to sql date
java.sql.Date sqlDate = new java.sql.Date(date4.getTime());
Upvotes: 1