Greetings all I want to do something like a trigger or a listener (I don't know what) that will listen on a specific database table, and with each new record inserted on this table, do some java code, I mean that it detects that a new record was inserted and get it's data if it's possible I need some guide about how this process can be accomplished ?
I am using Spring-Hibernate-PostgreSQL
The listener is a separate process that runs on the database server computer. It receives incoming client connection requests and manages the traffic of these requests to the database server.
STEP 1: Allocate a Connection object, for connecting to the database server. STEP 2: Allocate a Statement object, under the Connection created earlier, for holding a SQL command. STEP 3: Write a SQL query and execute the query, via the Statement and Connection created. STEP 4: Process the query result.
You probably want to look into the observer pattern. class Test { public static void main(String[] args) { Initiater initiater = new Initiater(); Responder responder = new Responder(); initiater. addListener(responder); initiater. sayHello(); // Prints "Hello!!!" and "Hello there..." } }
Create a listener in Oracle Database 19c with NETCALaunch the Network Configuration Assistant with necta command. Select “Listener Configuration” and click “Next“. Select “Add” then click “Next“. Give a name to the listener to easily identify it from other configured listeners and provide Oracle Home user password.
This is what LISTEN/NOTIFY was created for.
The only drawback is that you will need to have some kind of background thread that polls the database on a regular basis to see if any notifications are available.
You can also use the code from the Postgres Wiki to have a starting point
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With