aspose file tools*
The moose likes JDBC and the fly likes How to know when a table has new data? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to know when a table has new data?" Watch "How to know when a table has new data?" New topic
Author

How to know when a table has new data?

George Bendemann
Greenhorn

Joined: Dec 19, 2004
Posts: 2
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
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
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 ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Yu Tao
Greenhorn

Joined: Dec 12, 2004
Posts: 28
Originally posted by srini vasan:
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 ]


yes using Procedure is the best case.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30780
    
157

"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.

Thanks,
Jeanne
Forum Bartender


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rohit Ahuja
Ranch Hand

Joined: Oct 04, 2001
Posts: 121
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
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)
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30780
    
157

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
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to know when a table has new data?