Author
Conversion of string to date
Deepti Gupta
Ranch Hand
Joined: Jul 22, 2010
Posts: 30
Hi,
i'm trying to develop a module which reads the date from the Web page as inputed by the user and stores the date in the database.
My JSP page is as follows:
and the java file is as follows:
now when i'm trying to compile in the using ANT its giving the follwowing error:
please help
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1188
parse method has two overloaded forms
parse(String ) and parse(String source, ParsePosition pos)
but your code seems to be passing a Date object.
Swastik
Deepti Gupta
Ranch Hand
Joined: Jul 22, 2010
Posts: 30
the JSP page is sending the input as String only.
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1188
May be. But look at your method call
Deepti Gupta
Ranch Hand
Joined: Jul 22, 2010
Posts: 30
I made the changes and removed the parser from the statement where the method returns the value but it is still giving the same error for the one parser in the setDate method
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1188
Deepti Gupta
Ranch Hand
Joined: Jul 22, 2010
Posts: 30
i made the changes, now the code is:
and the error during compiling is:
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1188
Look at the error
so you should either throw the exception or catch it
Deepti Gupta
Ranch Hand
Joined: Jul 22, 2010
Posts: 30
Thanks... now the code gets compiled and is running..
but not according hoe it should..
the code is now..
its sending the date as "null"
I checked the logs and its something like this:
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1188
What is the use of following line?
private Date dates=null;
Deepti Gupta
Ranch Hand
Joined: Jul 22, 2010
Posts: 30
Its used for intializing and local declaration of the variable "dates"
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1188
try one thing, put two print statements in this method to make sure you are getting the values properly.
and in
Deepti Gupta
Ranch Hand
Joined: Jul 22, 2010
Posts: 30
I did the additions suggested by you. Now the log is:
The print statements in the setDate() weren't even executed.. so I think there might be a problem with that.
I even tried changing
public void setDate(String value)
to
void setDate(String value)
but that also gave the same result
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1188
try this once
in your execute method
make that dates variable as String
and change the definition of setDate and getDate as follows
Deepti Gupta
Ranch Hand
Joined: Jul 22, 2010
Posts: 30
Made the changes suggest by you. The code is now
and while compiling its giving an error:
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1188
should be
Deepti Gupta
Ranch Hand
Joined: Jul 22, 2010
Posts: 30
its giving an error "incompatible types"
so i made a change and converted
to
it compiled properly but while running struts gave an error:
Mai Vala
Greenhorn
Joined: Mar 31, 2010
Posts: 14
posted Jul 30, 2010 04:51:30
0
format method takes date datatype as method parameter and returns String...
Deepti Gupta
Ranch Hand
Joined: Jul 22, 2010
Posts: 30
I changed the code from
to
and it compiled and was able to execute.. but the "null" problem is still there.
the logs are:
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1188
There is small mistake in the code that Mai has pointed out, you need to call parse not format. However this does not seem to be related to the null issue.
Deepti Gupta
Ranch Hand
Joined: Jul 22, 2010
Posts: 30
I changed format to parse.... Only after making the change the file is able to be executed....
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1188
The problem is setter method for date is not getting called.
subject: Conversion of string to date