I am writing a program where i am fetching the records from an excel sheet and after getting those records i am trying to update it in database.
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.
# 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)
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
and you will get "2010-05-06" as output
Thanks Soumyajit Hazra,
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.
What is the type of "startdate"? Remember SimpleDateFormat returns java.util.Date and if you want to use setDate() you require java.sql.Date. So convert the util date object to sql date object. Check the Date API for the related conversion help.
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.
Also, Dinesh, I've modified your last post to decrease the indentation. That way the forum doesn't need horizontal scroll bars. Next time please keep your indentation a bit in check when posting code. We like proper indentation, but not if each line has an indentation of several tabs.