Oracle Change Notification Listener没有通知



我已经实现了Oracle Change Notification来监听Oracle数据库并将更改推送到Java侦听器。这招很管用。但是,由于某种原因,我不再收到来自数据库的任何更改通知。可能的结果是什么?我在Oracle文档中没有看到足够的信息。

我确实在USER_CHANGE_NOTIFICATION_REGS表中看到了注册的连接。但是我没有收到任何催促。

void run() throws SQLException {
    OracleConnection conn = connect();
    Properties prop = new Properties();
    prop.setProperty(OracleConnection.DCN_QUERY_CHANGE_NOTIFICATION, "true");
    DatabaseChangeRegistration dcr = conn.registerDatabaseChangeNotification(prop);
    // add the listenerr:
    dcr.addListener(new MyListener());
    // second step: add objects in the registration:
    Statement stmt = conn.createStatement();
    // associate the statement with the registration:
    ((OracleStatement) stmt).setDatabaseChangeRegistration(dcr);
    ResultSet rs = stmt.executeQuery("SELECT * FROM MY_TABLE where MY_FLAG = '3'");
    while (rs.next()) {
    }
    String[] tableNames = dcr.getTables();
    for (int i = 0; i < tableNames.length; i++) {
        System.out.println(tableNames[i] + " is part of the registration.");
    }
    rs.close();
    stmt.close();
}

public class MyListener implements DatabaseChangeListener {
    public void onDatabaseChangeNotification(DatabaseChangeEvent dce) {
        System.out.println("Change is found");
    }
}

我找到问题了。Oracle版本是10g。根据oracle,在11g之前的版本中不支持此操作:

从11g Release 1(11.1)开始,Oracle JDBC驱动程序提供了对Oracle Database的Database Change Notification特性的支持

最新更新