Results 1 to 5 of 5
Thread: query with a callback?
- 01-19-2012, 06:05 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
query with a callback?
Hi, I need to develop a program that will process entries in a database as they are added. In other words, whenever a new entry is added to table X, I want my program to process that entry in some way. Now, I could poll the database continually to check if there is a new entry, but I would much rather have a callback method that is called as soon as a new entry is added. Alternatively, since one of the fields is a timestamp, I would like to send a select * from table_x where time > last_time kind of query with a callback function that is called with the result of that query as soon as the result is not empty.
I have no idea if that's possible though, as I never really used JDBC nor am I very familiar with databases in general.
Thank you!
- 01-19-2012, 06:21 PM #2
Member
- Join Date
- Jan 2012
- Location
- Panamá
- Posts
- 41
- Rep Power
- 0
Re: query with a callback?
You can work with trigger
Database trigger - Wikipedia, the free encyclopedia
- 01-19-2012, 06:24 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: query with a callback?
Do you control what goes into the database?
(Not a fan of triggers, too much like 'magic')
- 01-19-2012, 06:47 PM #4
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
Re: query with a callback?
Thanks arielb, I will look into those, although the wikipedia article doesn't really explain how to use them. I'll do a quick google search to see what I can find.
@Tolls: What do you mean? The software that I need this "callback" for is a separate software from the one(s) that will input data into the database. I do not know who or what will input data into the database (well, I actually do, but I need to keep it generic, so as to allow new software to input data into the database without needing to re-code everything), although I do know some information on the nature of the data that will be input into it (I have the table definition and I know what is supposed to go into the time field for instance, so I know that a more recent entry should have a later "time" value). The software that input data into the database were/are/will be developed independently from the one I'm working on right now.
Not sure if that answers your question?
- 01-20-2012, 09:33 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: query with a callback?
OK, so it's not a single point of entry to the database (I didn't think it was likely, otherwise you probably wouldn't have asked the question).
Triggers are fired by the database on some event (ie insert or update or delete). For Oracle (which is where I know them from) you might use it for logging, or data manipulation before entry, or data validation.
You could set up a queuing or messaging service (just trying to think of existing techniques), and a trigger could insert into the relevant table? Then some form of JMS thing could monitor that and inform yor software of changes as and when they happen? You might be able to do something with Quartz, though it's not really what that was intended for (it's a scheduler rather than a messaging service).
Failing that you could jury-rig your own, as you thought about in the OP. One table that takes in enough information for you to identify what's happened, a trigger (or triggers) to populate it, then a simple Java thread that monitors it and calls your routines.
There isn't going to be a callback as you are asking the database (and we don't know which breed you are talking about) to call your Java. Which is nothing to do with JDBC.
Similar Threads
-
JNA-How to define a masage to recive callback?
By lipkerson in forum Advanced JavaReplies: 0Last Post: 05-28-2010, 12:10 PM -
Override Entity Callback Method
By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 12-13-2009, 06:05 AM -
Callback when window is done drawing/loading?
By rodrigo in forum SWT / JFaceReplies: 0Last Post: 08-21-2009, 02:01 AM -
Register a callback function in other class
By barts2108 in forum New To JavaReplies: 2Last Post: 11-10-2008, 04:24 PM -
Setting a timeinterval callback ???
By wallys in forum New To JavaReplies: 1Last Post: 08-19-2008, 05:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks