Java-oracle.jdbc.dcn.DatabaseChangeEvent-获取更改的行 [英] Java - oracle.jdbc.dcn.DatabaseChangeEvent - get changed row
问题描述
我正在使用oracle.jdbc.dcn.DatabaseChangeEvent来从Oracle DB中获取事件通知:
I'm using oracle.jdbc.dcn.DatabaseChangeEvent in order to get events notifications from my 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 ();
}
我的问题:是否有办法知道插入,更新,更改,删除了哪些行?
My question: Is there a way to know which exactly rows where inserted\updated\changed\dalteted?
我的目的是监视数据库并在发生某些特定事件时执行一些操作,因此我希望能够知道新的\更新的行值,以便通知监视系统(并且以避免对每个事件进行全表扫描.
My purpose is to monitor the DB and do some actions when some specific events occurs, so I want to be able to know the new\updated row values in order to notify the Monitoring system (And to avoid full table scan with every event).
重要说明:除了选择"功能之外,我无权访问数据库,因此此处无法使用触发器.
Important note: I do not have access to the DB beside the ability to "select", so triggers are not possible here.
谢谢.
推荐答案
如果调用 ROWID
s:
If you call registerDatabaseChangeNotification
with OracleConnection.DCN_NOTIFY_ROWIDS
set, you can use ROWID
s:
您的DatabaseChangeEvent
公开 RowChangeDescription[] getRowChangeDescription()
,您最终可以在其中获得 ROWID getRowid()
Your DatabaseChangeEvent
exposes a TableChangeDescription[] getTableChangeDescription()
function. If non-null
one object per changed table is included and RowChangeDescription[] getRowChangeDescription()
can be called, where you can finally get the ROWID
by calling ROWID getRowid()
您可能还需要评估getQueryChangeDescription()
的结果,在该数组的每个元素上调用getTableChangeDescription()
后,您还会得到TableChangeDescription
对象.
You may also need to evaluate the result of getQueryChangeDescription()
where you also get TableChangeDescription
-objects after calling getTableChangeDescription()
on each alement of the array.
ROWID
可以根据文档使用以选择或更新行存储在Oracle数据库中.
ROWID
can be used according to documentation to select or update rows stored in an Oracle DB.
这篇关于Java-oracle.jdbc.dcn.DatabaseChangeEvent-获取更改的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!