This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

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

thanks
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?

Regards
Raza

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..?

Regards
Raza
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

You probably need to convert the sql date to character.

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

http://developer.postgresql.org/pgdocs/postgres/functions-formatting.html


Swastik
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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();
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: date problem
 
Similar Threads
WA #1.....word association
Cannot be applied to (java.io.PrintWriter) error
Passing parameters between actions
How can I get sysdate in java?
Returning of More than one resultset