• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

conversion of string into java.util.Date

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
i have a problem related to string conversion in java.util.Date data type so that it can be inserted into the data base so for this telll me how

what i did till now is:---

String adate="";
java.util.Date a_date=null;

SimpleDateFormat ts= new SimpleDateFormat("dd-MMM-yyyy");
adate=request.getParameter("1-sep-2000");
try{
if((adate!=null)&& (!(adate.equals(""))))
{
a_date = (java.util.Date) ts.parse(adate);
}
}catch(ParseException e) {
System.out.println("Unable to parse " + e);
}

out.println("a_date:--"+a_date+"<br>");

but when i run this code the out put will be :--

java.text.ParseException: Unparseable date: "null"
at java.text.DateFormat.parse(DateFormat.java:334)
at jsp_servlet.__dod._jspService(dod.jsp:164)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
(ServletStubImpl.java:971)

but as u can see the value in string is not null but it can not parse that value so tell me the solution
thanks alot for your kind help
 
vikassheel gupta
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here the string is like request.getParameter("text1"); instead of request.getParameter("1-sep-2000")
thanks
 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like your request.getParameter() is returning a String literal "null".
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
request.getParameter() takes an argument that's a name of the parameter that comes in the request. Do not hardcode the date. I guess you get the date from a form field and pass it in the request. Pass the name of the form field.
 
vikassheel gupta
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
the value comes from the prev page is fine it is "9-sep-2000" but when we try to change it or we can say we try to parse it , it shows the parsing error so tell me how can i
or leave all that just tell me ur code how will you convert a string into java.util.Date
thanks alot
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lets try this pattern
"d-MMM-yyyy"
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic