Parsing String to Time and insert in mysqldatabase
- by kawtousse
Goal: Parse a string from an input type text into TIME type to be inserted in MYSQL Database.
String start= request.getParameter("startp");
System.out.println("start:" +start);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
long ms=0;
try {
ms = sdf.parse(start).getTime();
System.out.println(" the value of ms is:" +ms);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Time ts = new Time(ms);
System.out.println("the value of ts is:" +ts);
start:14:12 (value witch i entered actually in the form at the start field named startp)
the value of ts is :01:00:00
java.text.ParseException: Unparseable date: "14:12" at java.text.DateFormat.parse(Unknown Source)
ms not displayed
I ensure that database type of the following parameter is TIME.
Thanks.