| Author |
conversion of string into java.util.Date
|
vikassheel gupta
Ranch Hand
Joined: Aug 02, 2005
Posts: 53
|
|
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
|
Warm Regards<br />vikassheelgupta<br />9911005168
|
 |
vikassheel gupta
Ranch Hand
Joined: Aug 02, 2005
Posts: 53
|
|
Here the string is like request.getParameter("text1"); instead of request.getParameter("1-sep-2000") thanks
|
 |
Satish Chilukuri
Ranch Hand
Joined: Jun 23, 2005
Posts: 266
|
|
|
Looks like your request.getParameter() is returning a String literal "null".
|
 |
Sravan Kumar
Ranch Hand
Joined: Sep 11, 2005
Posts: 121
|
|
|
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.
|
keep smilin :: sravan<br /><a href="http://sravanpens.blogspot.com" target="_blank" rel="nofollow">I scribble here</a>
|
 |
vikassheel gupta
Ranch Hand
Joined: Aug 02, 2005
Posts: 53
|
|
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
|
 |
David Ulicny
Ranch Hand
Joined: Aug 04, 2004
Posts: 724
|
|
Lets try this pattern "d-MMM-yyyy"
|
SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
|
 |
 |
|
|
subject: conversion of string into java.util.Date
|
|
|