Results 1 to 5 of 5
  1. #1
    Filobel is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default 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!

  2. #2
    arielb is offline Member
    Join Date
    Jan 2012
    Location
    Panamá
    Posts
    41
    Rep Power
    0

    Default Re: query with a callback?


  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: query with a callback?

    Do you control what goes into the database?

    (Not a fan of triggers, too much like 'magic')

  4. #4
    Filobel is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default 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?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default 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

  1. JNA-How to define a masage to recive callback?
    By lipkerson in forum Advanced Java
    Replies: 0
    Last Post: 05-28-2010, 12:10 PM
  2. Override Entity Callback Method
    By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 12-13-2009, 06:05 AM
  3. Callback when window is done drawing/loading?
    By rodrigo in forum SWT / JFace
    Replies: 0
    Last Post: 08-21-2009, 02:01 AM
  4. Register a callback function in other class
    By barts2108 in forum New To Java
    Replies: 2
    Last Post: 11-10-2008, 04:24 PM
  5. Setting a timeinterval callback ???
    By wallys in forum New To Java
    Replies: 1
    Last Post: 08-19-2008, 05:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •