views:

68

answers:

2

I use a jquery datepicker then i read it in my servlet like that:

String dateimput=request.getParameter("datepicker");//1 then parse it like that:

System.out.println("datepicker:" +dateimput);  
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy");               
    java.util.Date dt = null;
    try
    {
        dt = df.parse(dateimput);
        System.out.println("date imput parssé1 est:" +dt);
        System.out.println("date imput parsée2 est:" +df.format(dt));

    } catch (ParseException e)
   {
        e.printStackTrace();
    }

and insert query like that:

String query = "Insert into dailytimesheet(trackingDate,activity,projectCode) values ("+df.format(dt)+", \""+activity+"\" ,\""+projet+"\")";

it pass successfully untill now but if i check the record inserted i found the date: 01/01/0001 00:00:00

l've tried to fix it but it still a mess for me.

+2  A: 

You have to pass the Date in the format: "yyyy-MM-dd"

Hinek
@kawtousse but it is answer to your noob question and worth at least upvoting
Col. Shrapnel
And yes, I totally agree with Guillaume that you SHOULD USE PreparedStatements for security and readability reasons!
Hinek
+4  A: 

Use PreparedStatements, they have a setDate(...) method.

Seriously, please use PreparedStatements! especially in a webapp context. You'll be facing SQL injections otherwise

Guillaume