hello everyone..
im trying to insert date into mysql..the field is of date type
bt when i select a date from datepicker and insert it into database,it takes a random date..not getting where the problem is..
the code is as follow

   SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    java.sql.Date d = null;

    Date parsed = null;
    try {
        parsed = format.parse(request.getParameter("dt"));
        if (parsed != null) {
            d = new java.sql.Date(parsed.getTime()); //parsed.getTime(
        } else {

            d = new java.sql.Date(new Date().getTime());
    } catch (ParseException e1) {

    String nature = request.getParameter("call_nature");
    String name = request.getParameter("c_name");
    String cat = request.getParameter("call").toString();
    String num = request.getParameter("phone_no");
    String street = request.getParameter("streetno").toString();
    String rbut = request.getParameter("c_room");
    String val = request.getParameter("hidd");

    String zone = request.getParameter("combo1").toString();
    String div = request.getParameter("combo2");
    String hrs = request.getParameter("hr1");
    String mns = request.getParameter("mn1");
    String am = request.getParameter("ap1");
    String occup = request.getParameter("occu");

    try {
        String connectionurl = "jdbc:mysql://localhost:3306/fms";
        String user = "root";
        String pass = "root";
        Connection con = DriverManager.getConnection(connectionurl, user, pass);

        String sql = "insert into fire_reg values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        PreparedStatement prst = con.prepareStatement(sql);
        prst.setString(1, nature);
        prst.setString(2, cat);
        prst.setString(3, name);
        prst.setString(4, num);

        prst.setString(5, val);
        prst.setString(6, street);
        prst.setDate(7, d);
        prst.setString(8, rbut);
        prst.setString(9, zone);
        prst.setString(10, div);
        prst.setString(11, hrs);
        prst.setString(12, mns);
        prst.setString(13, am);
        prst.setString(14, occup);

        if (prst.executeUpdate() == 1) {
            request.setAttribute("loc", street);
            request.setAttribute("phone", num);
            request.setAttribute("calltypee", cat);
            request.setAttribute("zonee", zone);

            RequestDispatcher rd = request.getRequestDispatcher("FMS14_DelhiRegMap.jsp");
            rd.forward(request, response);
    } catch (Exception e) {

pls help..thanks

Care to share what solved your problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.