使用java监控oracle数据库的变化,主要是针对表数据,如果发生变化,使用select去查询,能够达到推送的目的

 package com.test.notifi;

 import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleDriver;
import oracle.jdbc.OracleStatement;
import oracle.jdbc.dcn.DatabaseChangeEvent;
import oracle.jdbc.dcn.DatabaseChangeListener;
import oracle.jdbc.dcn.DatabaseChangeRegistration;
import oracle.jdbc.pool.OracleDataSource; public class TestNotification { public void run(){
OracleDataSource dataSource;
try {
dataSource = new OracleDataSource();
dataSource.setUser("hw");
dataSource.setPassword("112311");
dataSource.setURL("jdbc:oracle:thin:@198.22.1.4:1521:COPYDB1");
OracleConnection conn = (OracleConnection) dataSource.getConnection(); Properties prop = new Properties();
prop.setProperty(OracleConnection.DCN_NOTIFY_ROWIDS,"true");
prop.setProperty(OracleConnection.DCN_QUERY_CHANGE_NOTIFICATION,"true");
DatabaseChangeRegistration dcr = conn.registerDatabaseChangeNotification(prop); DCNDemoListener list = new DCNDemoListener(this);
dcr.addListener(list); Statement stmt = conn.createStatement(); ((OracleStatement)stmt).setDatabaseChangeRegistration(dcr);
// ResultSet rs = stmt.executeQuery("select * from hs_secu.entrust a where a.fund_account = '610005385'");
ResultSet rs = stmt.executeQuery("select * from stocc");
while (rs.next())
{}
String[] tableNames = dcr.getTables();
for(int i=0;i<tableNames.length;i++)
System.out.println(tableNames[i]+" is part of the registration.");
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace(); }
} public static void main(String[] a) {
TestNotification notification = new TestNotification();
notification.run();
} }
 package com.test.notifi;

 import oracle.jdbc.dcn.DatabaseChangeEvent;
import oracle.jdbc.dcn.DatabaseChangeListener; class DCNDemoListener implements DatabaseChangeListener
{
TestNotification demo;
DCNDemoListener(TestNotification dem)
{
demo = dem;
}
public void onDatabaseChangeNotification(DatabaseChangeEvent e)
{
Thread t = Thread.currentThread();
System.out.println("DCNDemoListener: got an event ("+this+" running on thread "+t+")");
System.out.println(e.toString());
synchronized( demo ){ demo.notify();}
}
}

使用windows机器去运行这个程序的时候,请注意,hostname需要添加自己的IP和主机名称

例如:  198.28.1.2 TIM-PC

这样oracle数据库才能知道是谁注册的

Database Change Notification的更多相关文章

  1. PIC32MZ tutorial -- Change Notification

    In my last post I implement "Key Debounce" with port polling, port polling is not very eff ...

  2. Up-to-date cache with EclipseLink and Oracle

    Up-to-date cache with EclipseLink and Oracle One of the most useful feature provided by ORM librarie ...

  3. MongoDB Change Stream:简介、尝试与应用

    在MongoDB3.6引入的新feature中,change stream无疑是非常吸引人的. Change streams allow applications to access real-tim ...

  4. iOS开发——OC篇&消息传递机制(KVO/NOtification/Block/代理/Target-Action)

     iOS开发中消息传递机制(KVO/NOtification/Block/代理/Target-Action)   今晚看到了一篇好的文章,所以就搬过来了,方便自己以后学习 虽然这一期的主题是关于Fou ...

  5. Database(Mysql)发版控制二

    author:skate time:2014/08/18 Database(Mysql)发版控制 The Liquibase Tool related Database 一.Installation ...

  6. Obtaining Directory Change Notifications(微软的例子,使用FindFirstChangeNotification,FindNextChangeNotification,FindCloseChangeNotification API函数)

    An application can monitor the contents of a directory and its subdirectories by using change notifi ...

  7. CMU Database Systems - Embedded Database Logic

    正常应用和数据库交互的过程是这样的, 其实我们也可以把部分应用逻辑放到DB端去执行,来提升效率 User-defined Function Stored Procedures Triggers Cha ...

  8. PHP7函数大全(4553个函数)

    转载来自: http://www.infocool.net/kb/PHP/201607/168683.html a 函数 说明 abs 绝对值 acos 反余弦 acosh 反双曲余弦 addcsla ...

  9. Microsoft Win32 to Microsoft .NET Framework API Map

    Microsoft Win32 to Microsoft .NET Framework API Map .NET Development (General) Technical Articles   ...

随机推荐

  1. 微信小程序中-折线图

    echarts配置项太多了,还是一点点积累吧~~~~~ 当然前提条件还是得老老实实看echarts官方文档 :https://echarts.baidu.com/ 今天主要就介绍下我在工作中通过ech ...

  2. C++: 模板函数定义与声明分离;

    我们知道模板函数或模板类的定义一般都是和声明一起在头文件中,但是这样的话, 就暴露了内部实现,有什么办法能够将定义和声明进行分离呢? 答案是: 有的: 头文件: test.h; class test ...

  3. 分布式协调服务Zookeeper集群之ACL篇

    分布式协调服务Zookeeper集群之ACL篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.zookeeper ACL相关知识概览 1>.zookeeper官方文档(h ...

  4. HTML页面只能使用微信浏览器打开

    看到一个项目,刚开始还以为是APP,只能用微信打开.仔细看了下原来是个web项目,只是禁用了其他浏览器打开,只能用微信浏览器打开.加上前端页面用了类似mui的模板,就更像APP了. 百度了下,参考 h ...

  5. 五十八、linux 编程——UDP 编程 广播

    58.1 广播介绍 58.1.1 介绍 广播实现一对多的通讯 它通过向广播地址发送数据报文实现的 58.1.2 套接字选项 套接字选项用于修饰套接字以及其底层通讯协议的各种行为.函数 setsocko ...

  6. vue全局变量的使用

    新建一个VUE文件,声明一个变量,并且把它export. 在main.js中引入,并声明. 在其他地方使用,直接this就可以了.

  7. python flsak 框架

    1.flask  轻量级微型web框架 优点:微框架.简单.可扩展 将flask变量实例化到app变量中 如果想要flask自动加载修改后的代码,要app.run(debug=True) 2.路由和视 ...

  8. iTOP-4418开发板所用核心板研发7寸/10.1寸安卓触控一体机

    iTOP-4418开发板所用核心板研发7寸/10.1寸安卓触控一体机 作为重中之重的电源管理选型,经多方对比测试最终选用AXP228,并得到原厂肯定 预留锂电池接口,内置充放电电路及电量计,可轻松搞定 ...

  9. selenium+webservice进行百度登录

    from selenium import webdriverimport time driver = webdriver.Chrome()driver.get("https://www.ba ...

  10. css3新单位vw、vh、vmin、vmax的使用详解(转载)

    文章传送门: https://blog.csdn.net/ZNYSYS520/article/details/76053961