SUSH SUSH -4 years ago 133
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 ?

Answer Source
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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download