File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes java.text.ParseException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.text.ParseException" Watch "java.text.ParseException" New topic
Author

java.text.ParseException

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

I am developing an web application for RMA and use AJAX to generate reports. So i am in need to send some values to some JSP file and receive the data from JSP page and displayed it in the Page using AJAX. Things getting better when i use string type as parameter. When i use the date as a parameter to the JSP page it shows an java.text.parseException in the console. Please let me know what's wrong i made with it.
Here is my code....Please help me friends...

This is the code where i get the parameters passed by AJAX....

: Edited :


Never try to be a hard-worker. Be a smart-worker.
My Blog
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

What DO the input dates look like?? are they in the format "yyyy-MM-dd"??


Regards, Rene Larsen
Dropbox Invite
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

I will also suggest that you use a PreparedStatement instead of a hard coded SQL.

Like this:otherwise you need to know the right date format of the database.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Originally posted by Rene Larsen:
What DO the input dates look like?? are they in the format "yyyy-MM-dd"??


they are in this format "yyyy/MM/dd"
and using prepared statement is also no use////
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Well then you have answered your own question...

"yyyy/MM/dd" and "yyyy-MM-dd" don't have the same format.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Originally posted by Rene Larsen:
Well then you have answered your own question...

"yyyy/MM/dd" and "yyyy-MM-dd" don't have the same format.


But yyyy-MM-dd is the default date format in MySQL and so i use this..... How this go wrong...? Please explain me....
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

You are getting the ParseException when you call "DATE_FORMAT.parse(..)" with a date format different from the one you have configured DATE_FORMAT (SimpleDateFormat object) with, which has the format "yyyy-MM-dd" - and you said that your input date has the format "yyyy/MM/dd"

These two date formats are not the same - and they have to.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Originally posted by Rene Larsen:
You are getting the ParseException when you call "DATE_FORMAT.parse(..)" with a date format different from the one you have configured DATE_FORMAT (SimpleDateFormat object) with, which has the format "yyyy-MM-dd" - and you said that your input date has the format "yyyy/MM/dd"

These two date formats are not the same - and they have to.


If i put the DATE_FORMAT as yyyy/MM/dd , then in MYSQL the date added like this.... 0000-09-21.... And this is displayed in report,,, I want the MySQL to store whatever format i like....Please give me some hints or code snippets to achieve this...
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

When you use a PreparedStatement and set the date(s) on it with '?', it will always match the database's date format. The 'date' field in the database have to be of type DATE or TIMESTAMP.

The input parameter 'q' and 'x' must match the pattern given to SimpleDateFormat.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Ok.... i got it..But here the monster comes... When i retrieve the date from db it displays in the default date format and how do i make it to display in dd/MM/yyyy format...?
Sorry for such silly questions because i am a beginner to this....
[ September 15, 2008: Message edited by: Rajkumar balakrishnan ]
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

You need to use the SimpleDateFormat object - or a new one with another pattern, and then use the 'format(java.util.Date)' method instead.

To get a 'java.util.Date' from a 'java.sql.Date', you can do it like this
[ September 15, 2008: Message edited by: Rene Larsen ]
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Originally posted by Rene Larsen:
You need to use the SimpleDateFormat object - or a new one with another pattern, and then use the 'format(java.util.Date)' method instead.

To get a 'java.util.Date' from a 'java.sql.Date', you can do it like this





So, where to put the format code here.... Please help me...
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Fix the problem.... Thanks Rene for your kind help and time for me....

I love Javaranch...
 
Don't get me started about those stupid light bulbs.
 
subject: java.text.ParseException