tags:

views:

54

answers:

2

How we cast a string into time type with mysql in java So String------->java.sql.time

thanks.

+1  A: 

You can use this code:

java.sql.Time.parse("String");

But that's deprecated, and replaced by DateFormat Parse http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html

Javier Parra
+3  A: 

It depends entirely on the format of your String, so I would use a SimpleDateFormat to parse the string into a java.util.Date; then you can extract the millisecond time value from that Date and pass it into a java.sql.Time(). Like this:

String s = /* your date string here */;
SimpleDateFormat sdf = new SimpleDateFormat(/* your date format string here */);
long ms = sdf.parse(s).getTime();
Time t = new Time(ms);
Matt Ball