1

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")?

2
  • 1
    This question has been asked and answered many times before on this site and elsewhere, q.v. this post for example. Commented Apr 1, 2015 at 14:07
  • Can I insert the format of date ("dd-MON-YYYY") in a date column? Commented Apr 1, 2015 at 14:09

1 Answer 1

1

Convert util date to sql date

    java.sql.Date sqlDate = new java.sql.Date(date4.getTime());
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer... Is there a way is there a way to insert the field in the format of date ("dd-MON-YYYY") of type date?
From java side you just specify that its sql. Now its upto DB vendor, how to represent that date. You need to check it for your DB vendor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.