Inside a jsp file, I have passed an element of input type="date" and I want to insert that element to the column of type Date inside the database. When I pass this,
<input type="date" class="well well-sm" id="startDate" name="startDate">
and receive it inside the servlet as:
String date=request.getParameter("startDate");
p.setFromDate(date);
When I printed the date, I'm getting 2018-05-24 which is the input I'm passing, which is in the required 'yyyy-MM-dd' format. I'm getting this date inside another class in the below format:
SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd");
java.util.Date ufromdate=sdf1.parse(p.getFromDate());//p.getFromDate()returns a string which has been assigned the value passed from the input element of type date.
java.sql.Date sqlfromdate=new java.sql.Date(ufromdate.getTime());
ps.setDate(5,sqlfromdate );
Here I'm getting ParseException even though I followed the correct pattern given as a reference in other answers written for similar questions in StackOverflow. I'm still getting this exception.
sdf1.parse:if (!"2018-05-24".equals(p.getFromDate())) throw new RuntimeException("["+p.getFromDate()+"]");(just for debugging purposes).