SUSH SUSH - 10 months ago 39
MySQL Question

Inserting date field into database using jsp with different date formats

I am trying to save the date field into mysql table.
The date field in my jsp form is in format MM/DD/YYY and in database as YYYY/MM/DD.
How can I retrieve the date from form and insert into the table with YYYY/MM/DD format ?

String publishdt = request.getParameter("publish");
if(publishdt == null)
    publishdt = "";
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
            LocalDate date = LocalDate.parse(publishdt, formatter);
            publish = String.format("%s", date);
    catch (DateTimeParseException exc) 
            out.println("%s is not parsable!%n"+publish);
            throw exc;      // Rethrow the exception.
        // 'date' has been successfully parsed