Now i am able to fetch the records but i am not able to set the date field in database.
In excel sheet the date is in date field format. So how can i fetch the date field from excel sheets.
This is what i have done
And this is what i get output for printing strdate
The error shows that i am not able to parse the date.
So what should i do in this case.
If you are using Apache POI for accessing the excel sheet then you can use getDateValue for a Cell. This is more better approach instead of reading it as a string value and then converting it.
But in excel sheet i have set that field as "YYYY-MM-DD" format. So how i am getting the time here.
Shall i set that field to text format in excel sheet and see the changes???
From the exception we can see that "06 05 2011 12:00:00" is the string you are trying to format and which is not yyyy-mm-dd. You can use something like this
# java.text.ParseException: Unparseable date: "06 05 2011 12:00:00"
# at java.text.DateFormat.parse(DateFormat.java:337)
# at summerinterndates.Main.contentReading(Main.java:143)
# at summerinterndates.Main.init(Main.java:51)
# at summerinterndates.Main.main(Main.java:290)
and you will get "2010-05-06" as output
What i have done is format the date field in excel sheet as a text field. I was successfully able to get the date in format i wanted.
But now there is an other problem which i am facing right now.
the line which is marked bold, i am getting an error there. Where my netbeans specify me to do "stmt.setDate(1, (java.sql.Date) startdate);" but again in gives an exception while updating the table that "Error: java.util.Date cannot be cast to java.sql.Date" so what should be done in this case.
Dinesh Remje wrote:I am usin jxl approach.
JXL also has proper support for dates. Cell has a sub interface DateCell which has methods to get both the Date object and the DateFormat used. So just cast the current Cell to DateCell and use its getDate() method.