Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sql query involving dynamic date

 
Shivaprasad P Kanaganahallimath
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String query="SELECT SCOREID FROM score where DATETIME between '08-apr-08' and '10-apr-08'";
works fine in java but how to give the date using any variable (String/date)


i tried like this, but doesn't work

String h="08-apr-08";
String query="SELECT SCOREID FROM score where DATETIME between "+h+" and '10-apr-08' "
this gives me invalid column name exception
could you people suggest me whats wrong?



thanks in advance
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to surround the "h" variable with single quotes, like you did with '10-apr-08'.
 
Shivaprasad P Kanaganahallimath
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer thank you so much, it's a silly mistake.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic