Public static void main (String [] args) throws SQLException {
OracleDataSource dataSource=new OracleDataSource ();
The dataSource. SetUser ("... ");
The dataSource. SetPassword ("... ");
The dataSource. SetURL (" JDBC: oracle: thin: @ 127.0.0.1:1521: oracle ");
Final OracleConnection conn=(OracleConnection) dataSource
The getConnection ();
Properties prop=new Properties();
Prop. SetProperty (OracleConnection DCN_NOTIFY_ROWIDS, "true");//to get change records the rowid
Prop. SetProperty (OracleConnection NTF_QOS_PURGE_ON_NTFN, "true");
//set the timeout, here is one hour, when the resources of the database and the drive automatically released, if you don't set to 0 or, in not expired, until the program to stop listening, when the database update notice sending, because there is no listener port, then release resources database
Prop. SetProperty (OracleConnection NTF_TIMEOUT, "0");
Final DatabaseChangeRegistration DatabaseChangeRegistration=conn
RegisterDatabaseChangeNotification (prop);
DatabaseChangeRegistration. AddListener (new DatabaseChangeListener () {
@ Override
Public void onDatabaseChangeNotification (DatabaseChangeEvent DatabaseChangeEvent) {
TableChangeDescription [] TDS=databaseChangeEvent
GetTableChangeDescription ();
Long regId=databaseChangeEvent. GetRegId ();
System. The out. Println ("============================="+ new Date () +"=============================");
If (regId==databaseChangeRegistration. GetRegId ()) {
System. The out. Println (" 'TableChangeDescription' (changes in the data table number) : "+ TDS. Length);
For (TableChangeDescription td: TDS) {
System. The out. Println (" database table id: "+ td. GetObjectNumber ());
System. The out. Println (" data table name: "+ td. GetTableName ());
//get the returned row level changes described the advising bank id, affect the line DML operations (row is inserted, updated, or deleted a)
RowChangeDescription [] RDS=td. GetRowChangeDescription ();
For (RowChangeDescription rd: RDS) {
System. The out. Println (" database table row level changes the rowid: "+ rd., getRowid () stringValue ());
System. The out. Println (" database table row level change: "+ rd., getRowOperation (). The toString ());
}
}
}
}
});
OracleStatement statement=(OracleStatement) conn. CreateStatement ();
The statement. SetDatabaseChangeRegistration (databaseChangeRegistration);
Statement. The executeQuery (" select * from TB_TEST where 1=2 ");
Statement. The executeQuery (" select * from TB_DEMO where 1=2 ");
The statement. The close ();
conn.close();
System. Err. Println (" open database change notification: ");
}
==================================line==========================================
I want to ask can get here listening to the operating table name, but the display is'??? ', this is the Oracle of the BUG? And Oracle on Oracle12 directly to canceled,
One he can access to and operation according to table a unique identifier (equivalent to a form of Id, note: would you like on the primary key), it should be a link to the club's official website introduces the class, but not a lot of introduction, the three methods, and the table Id remark is Oracle internal information, it is not made public?
Now that does not display the name of the table, the table of the only id, how to check, can through the query, and then to monitor this statement to check the table id, this is I want to own, but there is no this query in Oracle OJDBC listening,
===============================line=========================================
About the introduction of this class is too little, only three or four article, feel this is too practical, don't know is how to consider safety, to improve this class, and Oracle later to delete, do not support the,,, I desperately want to this class, so I can do real-time data synchronization, need not do regular tasks, (don't tell me to have own synchronization, I am the Oracle to Mysql synchronization, field is not very)
===============================line===============================================
Oracle in perfecting this listening you, don't shut him up,
CodePudding user response:
Can ask to Java area, jar package they are more professional, don't you move the past?CodePudding user response:
Move to ask next Java module