Hello,

I am trying to set up my website to be able to accept coupons. I am working in JSP and want to be able to get the current date and compare it to the date stored in the database. I have a field in the coupon table named 'Expiry' which is of type 'date'.

So far I have been able to retrieve the date from the database

...
out.print(rs.getDate("Expiry"));
}

and have printed it successfully

I am trying to do the following:

if(rs.getDate("Expiry") != null && rs.getDate("Expiry") < today){[INDENT]set coupon to invalid[/INDENT] 
}

I have tried setting 'today' up as a Date object:

<[email="%@page"]%@page[/email] language="java" import="java.sql.Date"%>
...
Date today = new Date();

but it says that it cannot resolve symbol and points at 'new'

I have also tried setting 'today' up as a Calendar object, but can not figure out how to make that work either.

Any help would be most appreciated as the company is planning on handing out coupons in just over a week!

Thanks in advance,
Dave.

Hey, I found the solution - turns out to be all mySQL... in case anyone is interested, here it is:

ResultSet rs = statement.executeQuery("select * from Coupons where Name='"+ coupon.getName() +"' and Expiry>=CURDATE()");
if(rs.isBeforeFirst() == rs.isAfterLast()){
coupon.setErrorFree(false);
rs = statement.executeQuery("select * from Coupons where Name='"+ coupon.getName() +"' and Expiry<CURDATE()");
... set coupon to invalid ...
}

Dave.

This article has been dead for over six months. Start a new discussion instead.