tags:

views:

28

answers:

1

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);
  1. start:14:12 (value witch i entered actually in the form at the start field named startp)
  2. the value of ts is :01:00:00
  3. java.text.ParseException: Unparseable date: "14:12" at java.text.DateFormat.parse(Unknown Source)
  4. ms not displayed

I ensure that database type of the following parameter is TIME.

Thanks.

+3  A: 

The value you entered, "14:12" does not match the format string "HH:mm:ss". Either input "14:12:00" or change the format string to "HH:mm"

Dean Harding