Hi, I need to set a date field in my html form. After submitting the form the request goes to the servlet and tha data will be stored in database. In servlets how can i retrieve the date field? Please help me.
-renu
Hi, I need to set a date field in my html form. After submitting the form the request goes to the servlet and tha data will be stored in database. In servlets how can i retrieve the date field? Please help me.
-renu
You'll get it out of the HttpRequest parameters:
DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
String dateAsString = httpRequest.getParameter("form-name-for-the-date-here");
Date dateAsObject = dateFormatter.parse(dateAsString);
If you're using Spring you should use their data binding API.
The above answer is good. If you want to change your format at database level use this format.
In PreparedStatement
:
to_timestamp( ? ,'dd-mm-yyyy %h:%i:%s')
format. to_date(dateAsString ,'DD-MM-RR HH24:MI:SS')
format.to_timestamp( ? ,'dd-mm-yyyy')
format.to_date(? ,'DD-MM-RR')
format.Set dateAsString
in PreparedStatement
.
String dateAsString = httpRequest.getParameter("form-name-for-the-date-here");