Java DB checking against Date/Time fields (event handling)?

Posted on 2011-10-22
Last Modified: 2012-05-12
How can I come up with a mechanism in java where I could monitor the date/time fields inside a Java DB table and as soon as the the date/time fields for one or many of the records match the system time I could grab them for further processing??!  Sample code would be appreciated!
Question by:snajalm
    LVL 2

    Expert Comment

    Hi, I think a little more details could help, is it something like:

    - Process A inserts records in the Java DB database, one of the table fields being a DATETIME
    - Process B watch that same table at a given interval of time (1 minute) to see if there are any records where DATETIME = now

    When you say "matching the system date", you mean to the second, minute, hour or day?
    Also, if process A and B in your system are within the same application, there might be better way for process B to be notified that there are records to be processed.
    LVL 2

    Accepted Solution

    Some databases include triggers which will perform an action when a table row is inserted or updated.  This might work better for you if the polling method that DataCruncher does not work for you.
    LVL 10

    Expert Comment

    Another option would be to load any rows that will occur within the next time period, T, and use a scheduled executor to start processes for those rows when they should occur.  You could then run the polling process after T has elapsed (or with some lead time to make sure anything that happens at T+0 is processed correctly).  The only difficulty with this approach is detecting any changes to the underlying database.  Triggers are a much safer way to go, but that's only if you can put all the logic in the database itself.


    Schedule a process that runs at the 50th minute of every hour.  This process runs the query:

    SELECT * FROM db_table WHERE time BETWEEN next_hour AND next_hour+one_hour;

    The returned items are then added to a scheduled processing queue (see java.util.concurrent API docs) and set up to run at their corresponding time.

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One Java Help from Top Experts

    Solve your toughest problems, fast.
    Java experts are online now and ready to help you.

    Suggested Solutions

    This article describes some very basic things about SQL Server filegroups.
    SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now