Question: I have a scenario where my Java program has to continuously communicate with the database table, for example my Java program has to get the data of my table when new rows are added to it at runtime. There should be continuous communication between my program and database.

If the table has 10 rows initially and 2 rows are added by the user, it must detect this and return the rows.

Answer: 
For HSQL you can use trigger. Ref: <http://hsqldb.org/doc/2.0/guide/triggers-chapt.html>

Trigger Action in Java

A trigger action can be written as a Java class that implements the org.hsqldb.Trigger interface. This interface has a single method which is called when the trigger is activated, either before or after the event. When the method is called by the engine, it supplies the type of trigger as an int value defined by the interface(as type argument), the name of the trigger (as trigName argument), the name of the table (as tabName argument), the OLD ROW (as oldRow argument) and the NEW ROW (as newRow argument). The oldRow argument is null for row level INSERT triggers. The newRow argument is null for row level DELETE triggers. For table level triggers, both arguments are null (that is, there is no access to the data). The triggerType argument is one of the constants in the org.hsqldb.Trigger interface which indicate the type of trigger, for example, INSERT\_BEFORE\_ROW or UPDATE\_AFTER\_ROW.

```
  CREATE TRIGGER t BEFORE UPDATE ON customer
   REFERENCING NEW AS newrow FOR EACH ROW
   BEGIN ATOMIC
     IF LENGTH(newrow.firstname) > 10 THEN
       CALL my_java_function(newrow.firstname, newrow.lastname);
     END IF;
   END

```
What do you mean by continuous communication? The connection to database should be kept open once established until you finish the task here. But you will have to keep polling to fetch new records.