Meaningless Drivel is fun!
The moose likes JDBC and Relational Databases and the fly likes sql query involving dynamic date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "sql query involving dynamic date" Watch "sql query involving dynamic date" New topic
Author

sql query involving dynamic date

Shivaprasad P Kanaganahallimath
Ranch Hand

Joined: Sep 25, 2006
Posts: 48
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


Shiva Prasad P.K.
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
You need to surround the "h" variable with single quotes, like you did with '10-apr-08'.
Shivaprasad P Kanaganahallimath
Ranch Hand

Joined: Sep 25, 2006
Posts: 48
Ulf Dittmer thank you so much, it's a silly mistake.
 
Have you checked out Aspose?
 
subject: sql query involving dynamic date
 
It's not a secret anymore!