我正在尝试使用 Oracle JDBC 注册来自 Oracle 表 (19c) 的更改通知。由于查询包含一个 JOIN 我正在使用 BEST 努力模式。我的用户已被“授予”更改通知权限。
在这一点上,我只是想让通知者接受任何查询。这不是最终版本,但我知道我们需要一个涉及两个表的查询。将查询更改为更简单的查询会SELECT * from SCDAT.SECURITIES WHERE SCDAT.SECURITIES.INSTYPE = 28
给出相同的输出。
测试代码
log.info("init changelistener");
log.info("Get datasource from Spring application context");
oracleDataSource = context.getBean("dataSource", OracleDataSource.class);
log.info("Cet Oracle connection from datasource");
oracle.jdbc.OracleConnection connection = (OracleConnection) oracleDataSource.getConnection();
Properties properties = new Properties();
properties.setProperty(OracleConnection.DCN_NOTIFY_ROWIDS, "true");
properties.setProperty(OracleConnection.DCN_QUERY_CHANGE_NOTIFICATION, "true");
properties.setProperty(OracleConnection.DCN_BEST_EFFORT, "true");
log.info("DCN property settings: {}", properties);
log.info("Register change notification to connection");
dcr = connection.registerDatabaseChangeNotification(properties);
//create statement
Statement stmt = connection.createStatement();
// associate the statement with the registration:
((OracleStatement) stmt).setDatabaseChangeRegistration(dcr);
log.info("Executing query {}", query);
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
// Do Nothing
}
log.info("attach listener to the processor");
dcr.addListener(this);
String[] tableNames = dcr.getTables();
for (int i = 0; i < tableNames.length; i++)
log.info(tableNames[i] + " is part of the registration.");
日志输出
2021-03-30 12:56:15.983 INFO 5180 --- [main] c.c.dbnotifier.OracleChangeListener : init changelistener
2021-03-30 12:56:15.983 INFO 5180 --- [main] c.c.dbnotifier.OracleChangeListener : Get datasource from Spring application context
2021-03-30 12:56:15.983 INFO 5180 --- [main] c.c.dbnotifier.OracleChangeListener : Cet Oracle connection from datasource
2021-03-30 12:56:16.061 INFO 5180 --- [main] c.c.dbnotifier.OracleChangeListener : DCN property settings: {DCN_QUERY_CHANGE_NOTIFICATION=true, DCN_BEST_EFFORT=true, DCN_NOTIFY_ROWIDS=true}
2021-03-30 12:56:16.061 INFO 5180 --- [main] c.c.dbnotifier.OracleChangeListener : Register change notification to connection
2021-03-30 12:56:16.077 INFO 5180 --- [main] c.c.dbnotifier.OracleChangeListener : Executing query SELECT SCDAT.TRANSMAIN.TRANSEX from SCDAT.TRANSMAIN,SCDAT.SECURITIES WHERE SCDAT.TRANSMAIN.SECIK = SCDAT.SECURITIES.SECIK AND SCDAT.SECURITIES.INSTYPE = 28
2021-03-30 12:56:16.295 WARN 5180 --- [main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oracleChangeListener': Invocation of init method failed; nested exception is java.sql.SQLException: ORA-29979: ikke støttet radstørrelse for endringsvarsling for spørringsresultat
此处解释了错误 ORA-29979 https://www.oraexcel.com/database-oracle-11gR2-ORA-29979,但根据 dbadmin,数据库上的 COMPATIBLE 设置为 19.0.0。
我应该补充一点,使用同一用户在 sqldeveloper 中运行查询可以正常工作。
关于如何进行的任何建议或想法?
/卡特琳娜