Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date problem

 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Elchin Asgarli
Ranch Hand
Posts: 222
Chrome Eclipse IDE Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your whole code, as well as database content.

and SELECT * is not a good thing to do.
 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi aditi,

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

Regards
Raza
 
Swastik Dey
Rancher
Posts: 1609
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's assuming Aditi is using PostgreSQL. For MySQL, SQL Server or Oracle it may be different. So Aditi, please TellTheDetails.
 
Murtaza Lokhandwala
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use java.util.Date dcode=new java.util.Date();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic