This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Need an event in a client program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Need an event in a client program" Watch "Need an event in a client program" New topic
Author

Need an event in a client program

Markus Hendersonicus
Greenhorn

Joined: Dec 20, 2010
Posts: 4
Hi folks, I have the Derby Network Server allowing database access to two network clients. One of the network clients adds a new record to the database. My question is: "How does the other client get told that a new record has been added?" There must be some mechanism for this! You can't implement any kind of useful system without it. I know I could write a trigger using SQL but how would this tell the other client of the new record that's just been added? Any help at all would be most welcome! Thanks in advance, Mark.

Ideally, what I'm after is the Derby Network Server doing something like firing a rowInserted() method or event in the Derby Network Client. It seems to me that this must be possible. It's how it would work if I'd designed it. I just can't find such a mechanism anywhere! This is driving me nuts. Please, if anybody can even hint to me where to look they will have my eternal thanks!

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Markus Hendersonicus wrote:There must be some mechanism for this! You can't implement any kind of useful system without it.


Well, no. There isn't any such mechanism but despite that millions of useful systems have been implemented world-wide.

So, if you want your database clients to cooperate like that, then you'll have to write your own server which acts as a front-end to the database and which does its own notifications. I don't recommend trying to use triggers to do the notification; if you do then you'll have to build something in the database which keeps track of listeners for various transactions and deals with what happens if the listeners went away without deregistering themselves and so on and so on.
Markus Hendersonicus
Greenhorn

Joined: Dec 20, 2010
Posts: 4
Thanks for the reply Paul! That explains why I couldn't find anything 'off the shelf' after 9 hours of googling!
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Just a side note: such feature exists in Oracle database; it's called Database Change Notification. It is targeted to middle tier servers caching data structures that seldom change. I'm currently battling with it in my project

This feature has the benefit that an application can react to changes that happened outside the applications itself. However, I agree with Paul, I would not try to implement something like this if the database did not support it naturally.
Markus Hendersonicus
Greenhorn

Joined: Dec 20, 2010
Posts: 4
Thank you Martin!

I have to say that it does surprise me a little bit that the Derby Network Server doesn't implement this. If the server could be asked to send either a notification (with or without the updated record itself) to selected clients on a filter then this would be pretty powerful. I guess this implemenetation wouldn't be scalable enough to solve 'real world' problems. I have implemented such a server using Windows Sockets in Visual Basic 6 and I was rather hoping there'd be an off the shelf solution. Hey, ho....
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Markus,

I'd say most databases don't have something like this. Even Oracle has added the feature quite recently (first appeared in 10g, enhanced a bit in 11g), and - frankly - it is not supposed to handle large data volumes. It is intended for a few tables that change very infrequently (eg. configuration tables), which is what we do. Although the notifications are handled asynchronously, imagine what it would do to the database row crunching ability if a single update statement changed thousands of rows in a single table. (Massive updates cause the notifications to be sent for a whole table, not for individual rows, but anyway.) It is in effect a little bit like triggers over the network.

The nice thing is we didn't have to implement our own notifications between different servers in our system. Reaction to external changes (eg. configuration made by the admin directly in the database) is a bonus we could do without. But that's about all.
Markus Hendersonicus
Greenhorn

Joined: Dec 20, 2010
Posts: 4
Thanks Martin!

So I guess I'd write my own server and inherit the Derby Network Server and have some kind of data listener so that the server has action events firing every time the database changes? I can then have code that posts updates to whichever clients are logged in. Something like that!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need an event in a client program
 
Similar Threads
Derby Embedded vs. Derby Network Server
Beta Question: UI
Passed SCJD (138)
Multiple Instances of Standalone
JDBC (ODBC) Concurrency confusion