Link to home
Start Free TrialLog in
Avatar of daydreamer6565
daydreamer6565

asked on

return statement not working properly

I am writing a code to check if the input date lies between the specified range..
My function does not return the modified string what could be the issue.. pls help..also check if my code is correct..
attaching the java code along with the jsp code..
java-code-for-date-check.txt
jsp-code-for-date-check.txt
Avatar of Umar Topia
Umar Topia
Flag of India image

You are not using the passed in value.

However, you are using the hadrcoded value
Date date1 = sdf.parse("2009-12-31");

Instead you should use it like:
Date date1 = sdf.parse(inpdt));
You need something like the following
PreparedStatement ps = con.prepareQuery("SELECT frmdt, todt FROM mydate WHERE ? BETWEEN frmt AND todt");
ps.setDate(1, java.sql.Date.valueOf("2009-12-31"));
rs = ps.executeQuery();

Open in new window

Avatar of daydreamer6565
daydreamer6565

ASKER

As guided by the Expert - umartopia , i have changed my code bt stil it does not retrive the string which is to be printed if the input date doesnt lie between the dates present in the database..
From your main class you have passed in the date in wrong format.

String x = objsecDate.funcdatechecker("2000-12-5");

Instead you should pass it like:
String x = objsecDate.funcdatechecker("2000-12-05");
I am giving the input as u suggested ,i also changed my connection string which had a mistake ..now else string that is "date doesnot lie between the range" gets printed even though i have given input as "2000-04-05"
my database contains 2 coloums 'frmdt' and 'todt' having values '2000-2-3' and '2000-7-3' repectively....
(i have also tried by giving input "2000-4-5")
ASKER CERTIFIED SOLUTION
Avatar of Umar Topia
Umar Topia
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks now it works properly!!
a. you don't need to concern yourself with date formats
b. selecting all dates and then filtering them programatically is unnecessary and inefficient