How can I know when a specific table has gotten a new row inserted into it? I want to my java program to maintain an open connection to Oracle all day and kick off jobs based upon the fact that a certain table has gotten a new row added to it. Any ideas?
Yu Tao
Greenhorn
Joined: Dec 12, 2004
Posts: 28
posted
0
I think you can use trigger.
when you table insert a new row. your trigger send the message to you java program and to tell you.
try..
Srinivasa Raghavan
Ranch Hand
Joined: Sep 28, 2004
Posts: 1228
posted
0
Yes i also agree with Yu Tao ..You can use a trigger.
But is it possible to call a Java Stored Procedure from a trigger. [ December 20, 2004: Message edited by: srini vasan ]
"RussianFriend RussianFriend", We're pleased to have you here with us in the JDBC forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Yes Russian, I think Tao is absolutely right. But my concern here is why do u wish to keep a connection from Java open ? When u write a trigger for it u can just forget about the connection(I mean the Java part). Oracle is good/capable enough to handle it from there.
Face Off.
George Bendemann
Greenhorn
Joined: Dec 19, 2004
Posts: 2
posted
0
Everyone says to use a trigger. But I have preexisting java code that does a lot of file i/o.....can this be done in a java stored procedure? Russian_Friend (George Bendemann)
George, Sure. Just have the trigger call the java stored procedure.
(Thanks for updating the display name)
David Harkness
Ranch Hand
Joined: Aug 07, 2003
Posts: 1646
posted
0
George,
If your requirements can handle a short delay between data appearing and your program processing it, you could simply poll the database from your application at a short, regular interval (every minute, every thirty seconds, whatever).
I tend to favor letting the database handle data storage and querying, period. If you have a lot of records to process, polling would allow you to run multiple applications simultaneously or take advantage of multithreading. And if you ever change the database or requirements, you won't be stuck rewriting the stored procedure again (true, not very likely).
Just another option to consider.
Mike Boota
Ranch Hand
Joined: Jul 18, 2002
Posts: 82
posted
0
Hi,
I am too designing the same i.e. poll on the table. I will have my program run as a windows service but just curious is it ok to keep the database connection open forever. As I am planning to just use one Database connection for all my updates selected inserts etc. and if no records to be processed the programs sleep for sometime and then again checks the table for new records. So I don't opne,close the connection and keep it open as long as the service is running. Any feedbacks on if it's ok to have the database connection open all the time and how to make sure that dbconnection object still valid.
Thanks
MB<br />Sun Certified Programmer for Java2 Platform