• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.text.ParseException

 
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 :
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What DO the input dates look like?? are they in the format "yyyy-MM-dd"??
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fix the problem.... Thanks Rene for your kind help and time for me....

I love Javaranch...
 
reply
    Bookmark Topic Watch Topic
  • New Topic