This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes conversion of string into java.util.Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "conversion of string into java.util.Date" Watch "conversion of string into java.util.Date" New topic

conversion of string into java.util.Date

vikassheel gupta
Ranch Hand

Joined: Aug 02, 2005
Posts: 53
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");
if((adate!=null)&& (!(adate.equals(""))))
a_date = (java.util.Date) ts.parse(adate);
}catch(ParseException e) {
System.out.println("Unable to parse " + e);


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

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

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")
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="" target="_blank" rel="nofollow">I scribble here</a>
vikassheel gupta
Ranch Hand

Joined: Aug 02, 2005
Posts: 53
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

SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
I agree. Here's the link:
subject: conversion of string into java.util.Date
It's not a secret anymore!