我正在使用 oracle.jdbc.dcn.DatabaseChangeEvent 来从 Oracle DB 获取事件通知:
public class TListener implements DatabaseChangeListener
{
...
public void onDatabaseChangeNotification(DatabaseChangeEvent e)
{
....
synchronized( changeNotification ){
changeNotification.notify();
}
}
}
而在另一个地方:
private void run(PropertiesConfiguration configuration) throws SQLException
{
OracleConnection conn = connect(configuration);
Properties prop = new Properties();
prop.setProperty(OracleConnection.DCN_NOTIFY_ROWIDS,"true");
prop.setProperty(OracleConnection.DCN_QUERY_CHANGE_NOTIFICATION,"true");
DatabaseChangeRegistration dcr = conn.registerDatabaseChangeNotification(prop);
try
{
// add the listenerr:
TListener list = new TListener(this);
dcr.addListener(list);
// 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 GTW_TX");
while (rs.next()){}
rs.close();
stmt. Close ();
}
我的问题:有没有办法知道插入\更新\更改\dalteted的确切行?
我的目的是监视数据库并在发生某些特定事件时执行一些操作,因此我希望能够知道新的\更新的行值为了通知监控系统(并避免每个事件进行全表扫描)。
重要提示:除了“选择”的能力之外,我无权访问数据库,因此这里不可能使用触发器。
谢谢。
如果你打电话registerDatabaseChangeNotification http://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleConnectionWrapper.html#registerDatabaseChangeNotification_java_util_Properties_ with OracleConnection.DCN_NOTIFY_ROWIDS
设置后,就可以使用ROWID http://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/sql/ROWID.htmls:
Your DatabaseChangeEvent
暴露了一个TableChangeDescription[] getTableChangeDescription() http://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/dcn/DatabaseChangeEvent.html#getTableChangeDescription__功能。如果非null
每个更改的表包含一个对象,并且RowChangeDescription[] getRowChangeDescription() http://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/dcn/TableChangeDescription.html#getRowChangeDescription__可以调用,在那里你最终可以得到ROWID http://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/sql/ROWID.html通过致电ROWID getRowid() http://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/dcn/RowChangeDescription.html#getRowid__
您可能还需要评估以下结果getQueryChangeDescription()
你还可以得到TableChangeDescription
-调用后的对象getTableChangeDescription()
在数组的每个元素上。
ROWID http://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/sql/ROWID.html可以根据使用文档 http://docs.oracle.com/cd/A84870_01/doc/java.816/a81354/oraint4.htm选择或更新存储在 Oracle DB 中的行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)