my dog learned polymorphism*
The moose likes JDBC and the fly likes problem in date comparing with db2 database,query is not executing    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in date comparing with db2 database,query is not executing    " Watch "problem in date comparing with db2 database,query is not executing    " New topic
Author

problem in date comparing with db2 database,query is not executing

saswat rashmi
Greenhorn

Joined: Jul 31, 2007
Posts: 14
hi everyone

i have one jsp page two text box
1. one for start date
2.second for end date
and for date selection have used datepicker

user selects the start date and end date .then clicks on view button
then i am retrieving these two dates on next jsp page .uptp here is ok

here i want display related data from db2 databse between these two dates(start date and end date)on next jsppage

but it is giving error my db2 dtabse uses the format of YYYY-MM-DD

the query i am not able execute

String strsql ="select voucher_master.VOUCHER_TYPE,voucher_master.VOUCHER_NO,dd_master.CHQ_DD_NO,dd_master.DD_DATE from voucher_master,dd_master Where voucher_master.VOUCHER_ID = dd_master.VOUCHER_ID and dd_master.DD_DATE >=" + fromdate + " and dd_master.DD_DATE <=" + todate + "";
it is giving error

please help me
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Change your query to use a PreparedStatement and bind your dates to parameters. This will remove the formatting mismatch.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
or... you could just use the SQL to_date function

to_date(my_field,"date_format of my field)
[ October 10, 2007: Message edited by: Paul Campbell ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in date comparing with db2 database,query is not executing