Eve Eve - 11 months ago 90
Java Question

Ping a table in the database with Java

I was wondering if it's possible to keep pinging a oracle table until a row is added to a table or removed.

I want to start the next action after I get a confirmation that the row has been added or removed. Preferred method is a query that keeps pinging until it happens.
Normally when querying I use executeQuery method but that only return when it has results

I haven't found a method yet that is able to do that.

So does anyone know a way to do this?

Answer Source

In Oracle 11g you could use Database Change Notification. Instead of polling the database to check for changes, you register to receive an event when a change occurs. There is a source code example here.

If you choose to poll instead, then you should consider your query carefully. For example, relying on number of rows in the table - SELECT COUNT(*) FROM your_table - could give you the wrong answer if the same number of rows were added and removed from the table between two executions of your query.