tags:

views:

55

answers:

1

When I do the following:

String start = request.getParameter("startp");
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");  
long ms=0;
try {
    ms = sdf.parse(start).getTime();
} catch (ParseException e1) {
    e1.printStackTrace();
}
Time ts = new Time(ms);

it is inserted with this value 01:00:00 witch is not the correct one (entered by user).

I don't understand the error here. Please help. Thanks

A: 

First, it's not casting, it's parsing (I have updated the title and the tags accordingly). Second, as per the SimpleDateFormat API document two-digit 24h-hours are to be represented by HH, not by hh.

To nail the root cause better down, you'll have to update your question to include the actual values of start, ms and ts. Print them using System.out.println() or a logger. If all looks fine, then the problem is in the SQL or the DB table model, you need to ensure that you're setting it using PreparedStatement#setTime() and that the DB table column type is of at least TIME type.

BalusC