MainstreamDeveloper00
MainstreamDeveloper00

Reputation: 8556

How can I check database field every day?Cron job?

I' m developing application in Java which is connected to database (Oracle or SQLite). In database I store contracts. The contract has field access_date. And i want to check this field once every day and if one day access_date will be equal to the current date then mark the contract as not valid. How can I implement this? In PHP as far as I know there are cron jobs for such tasks but what about java or java ee? How can I do this?Thanks in advance!

Upvotes: 1

Views: 2852

Answers (3)

David Aldridge
David Aldridge

Reputation: 52386

Instead of saving an attribute for the contract not being valid, and having to check it against sysdate every day, I would use a predicate such as "access_date < trunc(sysdate)" to find expired contracts, and an expression such as:

case when access_date < trunc(sysdate) then 'N' else 'Y' end

... to display whether a contract is active or not.

Upvotes: 0

goblinjuice
goblinjuice

Reputation: 3214

You can do this in two ways:

  1. You can use Cron to invoke a Java program at specific time (in your case, one every day).
  2. If your Java program is designed to run as service/daemon (staying in the background all the time), you can use a job scheduler such as Quartz Scheduler to invoke a certain check function at specific time.
  3. As an extension of 2., you can use ScheduledExecutorService.

Upvotes: 2

Juned Ahsan
Juned Ahsan

Reputation: 68715

Use either TimerTask or ScheduledTask. Here is a good tutorial for that:

http://www.ibm.com/developerworks/java/library/j-schedule/index.html

Upvotes: 0

Related Questions