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

How to know when a table has new data?

 
George Bendemann
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Yu Tao
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34084
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Rohit Ahuja
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
George Bendemann
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34084
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George,
Sure. Just have the trigger call the java stored procedure.

(Thanks for updating the display name)
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic