Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help on Database TABLE Listener

 
krishna Karthikk
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody, I am krishna, I am coding or an application where I need to execute a function or get a notice on command prompt or play an alarm whenever a record is inserted into a table.

The records will be inserted into the table from another java application running somewhere on the network.

Is there any such Database Table Listener.

Thank you all in advance. Have a nice day.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "listener" part is called a database trigger. If you want a trigger to notify you when it fires, then it can call a stored procedure -- for example, Java stored procedures in Oracle.
 
krishna Karthikk
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest thank you for the reply. Can you please tell me how to do the same thing with mysql database because its a free ware. I cant go for oracle.

Thank you in advance. Have a nice day.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid I don't know of any way to do it in MySQL. That doesn't mean there isn't a way, though, because this is not my area of expertise. Anybody?
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not my area of expertise either, but a bit of googling led me to the MySQL trigger FAQ page. I would guess that #13 may be the one relevant to krishna's question.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18008
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If free is the limiting factor, PostgreSQL might be the better choice. MySQL added stored procedures and related refinements relatively recently (MySQL 5). User-defined Functions (UDFs) have to be coded in C. In comparison, PostgreSQL has supported triggers, stored procedures and user-defined functions for a long time now, and alows a broader selection of languages to be used.

Of course, given a UDF that does an OS exec() call, you can do just about anything.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your definition of an alarm ?

Here is my suggestion. Write a trigger that will insert an event record into a separate table. Write a small app that will poll this event table for "alarm" records and send you an email when it finds one. Sound like the solution you want ?

What exactly are you trying to achieve here. What is the context of this problem ?
 
krishna Karthikk
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody, thank you for your replies. I found some problems with triggering model. Now I decided to do it using a time based job. I ll write a java program which continuously looks into the table for new records for every 5 minutes.

But for now, I want to start from the beginning, Actually I am working on a GSM application where 2 programs will be running on the system. One for receiving the messages and storing in the database. One for sending the replies.

The first part has been finished. Note, here the 2 applications are different. I mean 2 main()'s. So whenever a record is inserted the sender application has to some how know the insertion. Which is a tedious task. So I decided to go for Time Based Job.

Thank you all for the valuable replies. Have a nice day.
 
Billy Vandory
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:If free is the limiting factor, PostgreSQL might be the better choice. MySQL added stored procedures and related refinements relatively recently (MySQL 5). User-defined Functions (UDFs) have to be coded in C. In comparison, PostgreSQL has supported triggers, stored procedures and user-defined functions for a long time now, and alows a broader selection of languages to be used.

Of course, given a UDF that does an OS exec() call, you can do just about anything.


Yeah, I totally agree. I used to use mysql, but when I couldn't even use sequences I became concerned and moved to postgresql. LAMP should be renamed to LAPP. (sorry, didn't mean to insult any MySql people out there)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic