Parsing String to Time and insert in mysqldatabase

Posted by kawtousse on Stack Overflow See other posts from Stack Overflow or by kawtousse
Published on 2010-04-29T03:45:53Z Indexed on 2010/04/29 3:57 UTC
Read the original article Hit count: 341

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about java

Related posts about date