Having MySQL or MS SQL Server notify a Java progra

2019-06-12 12:03发布

问题:

I have a MySQL database (that I'll soon be moving over to MS SQL Server 2008/2012) which is accessed from a Java program I've written. Let's call this first program the "Display Program." Another Java program, which we'll call the "Updater Program," will be periodically adding data to the database. Currently, I have the Display Program on a timer that retrieves data from the database and updates its display every thirty seconds with that data. Is there any way to have the database "notify" that Display Program any time that data has been added to it, so I won't have to use a timer?

These two Java programs will be running on different computers on the network, so I don't see how to have a listener on the Display Program that the Updater Program can trigger, unless I find some way to do it through the network. (Which sounds like a whole lot of trouble.) Also, the Display Program keeps an open connection with the database, so perhaps the database can "see" that connection and somehow ping the Display Program on the other end of it to update itself?

If this isn't possible or it turns out to be extremely involved and difficult, just let me know and I'll stick with the 30-second-polling method that I'm currently using.