wood burning stoves 2.0*
The moose likes JDBC and the fly likes date problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "date problem " Watch "date problem " New topic
Author

date problem

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I have a html form from where I get date as Aug 8 2003 when I do
request.getPArameter("empdate")

When use this value in preparedsql ... my sql does not work.

I am using DB2 and When I try 'mm/dd/yy' in command center it works fine.

the emp date is stored in db as aug 6, 2003 ..but somehow it does not work when i use the same format to retrieve info. Why? and how to solve this problem
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

More about JBDC than JSP, so moving appropriately.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Shan,
Since you are using prepared statements, you don't need to worry about the date format for insertions. Try using setDate(). For example:

The driver will handle the format for you.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
for retrieving use,

rs.getDate(int i);

then parse it into any format you wish, using SimpleDateFormat class or Calendar.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
my select st is

select eno, ename where empdate between ? and ?

from the html form I get date as aug 8 2004 to sep 8 2004

when I use mm/dd/yyyy format it works fine but not with above format.

How do I convert my input to mm/dd/yyyy format?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Hi Shan,

Jeanne said something above. Else please paste some code snippet then we will know what are having really. and please paste the exception stack as well if there is any.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
http://javascript.internet.com/forms/val-date.html

I use the above code to validate my dates in my html page. the dates returned by them are like sep 5 2004

public emp get_emp()

select * from emp where emp_date between ? and ?

String dt1 = request.getparameter(date1)
String dt2 = request.getparameter(date2)

ps.setString(1,dt1);
ps.setString(2,dt2);
ps.executequery();

}

I get this error when I execute the sel st with date format as sep 8 2003
sep 9 2004 in command center

The syntax of string representation of a datetime value is incorrect

But when I use mm/dd/yyyy forrmat in command centre it works fine.


try{
Log.writeMessage(Log.LOG_LEVEL_DEBUG, "1");
String strTmp = "sep 21 2004";
Log.writeMessage(Log.LOG_LEVEL_DEBUG, "2");
java.util.Date dtTmp = new SimpleDateFormat("mon dd yyyy").parse(strTmp);
Log.writeMessage(Log.LOG_LEVEL_DEBUG, "3");
String strOutDt = new SimpleDateFormat("mm/dd/yyyy").format(dtTmp);
Log.writeMessage(Log.LOG_LEVEL_DEBUG, "strOutDt = " + strOutDt);
}catch(Exception ex){}

I just wrote the above program and I see the code is stuck at "bold " line
I get 1 and 2 as print but not three? Why?
Error I get is unparsebale date

[ October 07, 2004: Message edited by: shan javan ]
[ October 07, 2004: Message edited by: shan javan ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Shan,
The format should use "M" for the month rather than "mon".
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
lets take "January" as an example.

MM = 01
MMM = Jan
MMMMM = January

Single "M" is nothing.
"mon" is nothing.

for more, plz. read the docs.
[ October 07, 2004: Message edited by: adeel ansari ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: date problem
 
Similar Threads
Date conversions
Parsing a date and retaining the format
compatibility of date format
To_number function not work with decode function.
How to get a Date object with a specifed time