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
JSPJava

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
Umar Topia

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));
CEHJ

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

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..
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Umar Topia

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");
daydreamer6565

ASKER
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
Umar Topia

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
daydreamer6565

ASKER
Thanks now it works properly!!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
CEHJ

a. you don't need to concern yourself with date formats
b. selecting all dates and then filtering them programatically is unnecessary and inefficient