3

Currently I'm using JDBC templates to query the database for information. I'm constantly pinging the oracle DB to check if a table in particular has been updated, if it has, then I run a function, if not, then I wait a bit and ping it again.

    ReportsDao rDao = new ReportsDao();
    while(true)
    {
        List<ReportRequest> rr = rDao.selectAll();
        for (ReportRequest r: rr)
        {
            if(!r.getDone())
            {
                //do stuff
            }
        }
        try {
            Thread.sleep(10000);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    {

So my question is, how can I avoid this constant pinging of the database for new information? Is it possible to have a listener sit around that triggers what I want it to do once the table is updated?

Stupid.Fat.Cat
  • 10,755
  • 23
  • 83
  • 144

1 Answers1

0

When I was at college I heard that at that time Oracle provided a way to execute Java code at server side.

This link seems to prove that my memory isn't as bad as I thought.

Having this in mind, you could implement a socket listener at your db-client side and send a notification event from the socket-client at Oracle server triggered by a db event. As you may find in the documentation I linked above, is it possible to register a Java class method as a procedure in the database server.

If you don't want to use sockets you could try RMI.