Is polling the only way for updating app's data from a database?

In Oracle you can use the built in DBMS_ALERT package to facilitate this.

DBMS_ALERT supports asynchronous notification of database events (alerts). By appropriate use of this package and database triggers, an application can notify itself whenever values of interest in the database are changed.

Suppose a graphics tool is displaying a graph of some data from a database table. The graphics tool can, after reading and graphing the data, wait on a database alert (WAITONE) covering the data just read. The tool automatically wakes up when the data is changed by any other user. All that is required is that a trigger be placed on the database table, which performs a signal (SIGNAL) whenever the trigger is fired.


LISTEN / NOTIFY for PostgreSQL

http://www.postgresql.org/docs/current/static/sql-notify.html

in the database...

NOTIFY static_channel_name, 'static-message';

or in a function/trigger:

perform pg_notify('dynamic-channel-name', 'dynamic-message');

in the database client:

LISTEN some_channel_name; --note the lack of quotes

The LISTEN client will receive the PostgreSQL process ID, channel name, and message value.

The standard JDBC driver for PostgreSQL doesn't like notifications, however you can use the https://github.com/impossibl/pgjdbc-ng driver for this purpose


Certain database vendors also provide integrated message buses that your app can simply subscribe to:

  • Oracle Advanced Queueing
  • IBM DB2 with MQseries (now called WebSphere MQ)
  • Sybase RTMS

An alternative would be to route the data into the database in the first place via a message bus like Tibco/RV and simply "branch" it, on stream going into the DB and one going to your application, or use a caching layer like Coherence between your app and the DB.