Using event notification

You can use the jConnect event notification feature to have your application notified when an Open Server procedure is executed.

To use this feature, you must use the SybConnection class, which extends the Connection interface. SybConnection contains a regWatch method for turning event notification on and a regNoWatch method for turning event notification off.

Your application must also implement the SybEventHandler interface. This interface contains one public method, void event(String proc_name, ResultSet params), which is called when the specified event occurs. The parameters of the event are passed to event, which tells the application how to respond.

To use event notification in your application, call SybConnection.regWatch( ) to register your application in the notification list of a registered procedure. Use this syntax:

SybConnection.regWatch(proc_name,eventHdlr,option)

where:

Whenever an event with the designated proc_name occurs on the Open Server, jConnect calls eventHdlr.event from a separate thread. The event parameters are passed to eventHdlr.event when it is executed. Because it is a separate thread, event notification does not block execution of the application.

If proc_name is not a registered procedure, or if Open Server cannot add the client to the notification list, the call to regWatch throws a SQL exception.

To turn off event notification, use this call:

SybConnection.regNoWatch(proc_name)

WARNING! When you use Sybase event notification extensions, the application needs to call the close method on the connection to remove a child thread created by the first call to regWatch. Failing to do so may cause the Virtual Machine to hang when exiting the application.