File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "date problem" Watch "date problem" New topic

date problem

Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
i am using following query in my java page &its is returning null

("select * from tble where date='"+dcode+"';");

dcode is a variable containing date & time

please anyone help me

Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

hi Aditi,

Check your Query on the query browser what is it returning?
that may give you an idea that problem is in query or anywhere else?


Good luck!!
A small leak can sink a Gigantic ship.>
Elchin Asgarli
Ranch Hand

Joined: Mar 08, 2010
Posts: 222

Post your whole code, as well as database content.

and SELECT * is not a good thing to do.

Personal page, SCJP 6 with 91%, SCWCD 5 with 84%, OCMJD
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
@razar thanks for your reply
when i run same query on my db then it returns properly

@Elchin thanks for your reply too but that code is not with me & i am not using '*' i am using whole query

but i think problem is somewhere else

thanks for reply & sorry for inconvinience
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

hi aditi,

can you provide me the jsp code and the same Query you are using..?

Swastik Dey

Joined: Jan 08, 2009
Posts: 1584

You probably need to convert the sql date to character.

select * from tble where to_char(date,'the format you need')='"+dcode+"';"

Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

That's assuming Aditi is using PostgreSQL. For MySQL, SQL Server or Oracle it may be different. So Aditi, please TellTheDetails.

How To Ask Questions How To Answer Questions
Murtaza Lokhandwala
Ranch Hand

Joined: Jan 28, 2010
Posts: 35
use java.util.Date dcode=new java.util.Date();
I agree. Here's the link:
subject: date problem
It's not a secret anymore!