提问人:gilbert winiga 提问时间:5/24/2023 更新时间:5/24/2023 访问量:35
Quarkus 3.0.3.Final 中的 Oracle 数据库更改通知
Oracle database change notification in Quarkus 3.0.3.Final
问:
我是 oracle 数据库更改通知的新手。使用此代码,我在执行时出现异常,需要有关如何纠正此问题的帮助。stmt.execute("SELECT e.EMPLOYEE_ID, e.FIRST_NAME, e.LAST_NAME FROM EMPLOYEES e WHERE e.EMPLOYEE_ID > 1");
@ApplicationScoped
public class ChangeRegistrar {
@Inject
Logger log;
@Inject
DatabaseChangeNotificationListener listener;
@Inject
DataSource dataSource;
private DatabaseChangeRegistration dcr;
private OracleConnection conn;
public synchronized void register() throws SQLException {
try {
this.conn = this.dataSource.getConnection().unwrap(OracleConnection.class);
Properties prop = new Properties();
prop.setProperty(OracleConnection.DCN_QUERY_CHANGE_NOTIFICATION, "true");
prop.setProperty(OracleConnection.DCN_BEST_EFFORT, "true");
prop.setProperty(OracleConnection.DCN_CLIENT_INIT_CONNECTION, "true");
this.dcr = this.conn.registerDatabaseChangeNotification(prop);
this.dcr.addListener(listener);
OracleStatement stmt = this.conn.createStatement().unwrap(OracleStatement.class);
stmt.setDatabaseChangeRegistration(this.dcr);
// ResultSet rs = stmt.executeQuery("select * from employees");
if (dcr != null && dcr.getState().equals(NotificationRegistration.RegistrationState.ACTIVE)) {
stmt.execute("SELECT e.EMPLOYEE_ID, e.FIRST_NAME, e.LAST_NAME FROM EMPLOYEES e WHERE e.EMPLOYEE_ID > 1");
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
}
String[] tableNames = this.dcr.getTables();
for (int i = 0; i < tableNames.length; i++) {
System.out.println(tableNames[i] + " is part of the registration.");
}
rs.close();
} else {
log.fatal("Houston we got a problem here");
}
stmt.close();
} catch (SQLException ex) {
System.out.println(ex.getMessage());
unregister();
throw ex;
}
}
// rest of the code here
}
我找到了这段代码并使其工作,但是当我尝试与quarkus和AgroalDatasource一起使用时,我遇到了与代码相同的错误
也尝试了这个解决方案,但在我的情况下不起作用
答: 暂无答案
评论