wood burning stoves*
The moose likes JDBC and the fly likes Need help on Database TABLE Listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Need help on Database TABLE Listener" Watch "Need help on Database TABLE Listener" New topic
Author

Need help on Database TABLE Listener

krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
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.


There is no rule that we all should know everything. Lets learn few things of everything here.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
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

Joined: Jul 08, 2003
Posts: 24184
    
  34

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
Bartender

Joined: Oct 14, 2005
Posts: 18563
    
    8

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

Joined: Jun 25, 2001
Posts: 16054
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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 ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
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

Joined: Mar 23, 2010
Posts: 57
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help on Database TABLE Listener