I am importing data from a csv file via opencsv to insert into a mysql DB. opencsv imports as string and for 1 field in the DB I need to parse it to date in the format: yyyy-MM-dd. However I am getting an error.
// This is the string that I have extracted from the csv file
String elem1 = nextLine[0];
// printing out to console I can see the string I wish to convert
System.out.println(elem1); => 2015-08-14
// Below is my code to parse the date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date convertedCurrentDate = sdf.parse(elem1);
String date=sdf.format(convertedCurrentDate );
// printing date to console gives me 2015-08-14
System.out.println(date);
As mentioned above printing date out to console gives me 2015-08-14. However I get the error:
java.text.ParseException: Unparseable date: ""
Can someone give me some advice as to what I am doing wrong?
The line 'java.util.Date convertedCurrentDate = sdf.parse(elem1);' is the line causing the error.
Thanks!