I am using JDatechooser netbeans swing plugin for my desktop app development. By default its dateformat is mm/dd/yy but its not the format which the db required. I need to convert it to the yyyy-mm-dd format. I tried with SimpleDateformat class and it gives me the following error: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '8/29/11' for column 'registered_date' at row 1
can anyone give me a good solution to do this properly
Thanks
Try this:
Date date = ...
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String date_for_mysql = df.format(date);
See related SO answers here:
How to parse a date?
Java date formatting?
Converting MySql DateTime type into something more friendly
how to store java date type to mysql date type?
Convert Date into MYSQL Date Format
How to convert Date in String to Sql date?
How to set Current date to MySQL date column from Java?