opencsv を介して csv ファイルからデータをインポートして、mysql DB に挿入しています。opencsv は文字列としてインポートされ、DB の 1 つのフィールドについては、yyyy-MM-dd の形式で現在まで解析する必要があります。しかし、私はエラーが発生しています。
// 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);
上記のように、日付をコンソールに出力すると、2015-08-14 が返されます。ただし、次のエラーが表示されます。
java.text.ParseException: Unparseable date: ""
誰かが私が間違っていることについてアドバイスをくれますか?
「java.util.Date convertCurrentDate = sdf.parse(elem1);」という行 エラーの原因となっている行です。
ありがとう!