使用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. 第二周博客作业<西北师范大学|李晓婷>

    1.助教博客链接:https://home.cnblogs.com/u/lxt-/ 2.点评作业内容: https://www.cnblogs.com/dxd123/p/10494907.html#4 ...

  2. 最大似然估计与期望最大化(EM)算法

    一.最大似然估计与最大后验概率 1.概率与统计 概率与统计是两个不同的概念. 概率是指:模型参数已知,X未知,p(x1) ... p(xn) 都是对应的xi的概率 统计是指:模型参数未知,X已知,根据 ...

  3. fork子进程

    title: fork子进程 data: 2019/3/21 20:24:39 toc: true --- 这里实在学习socket编程前的小知识点,用来创建多个服务端 学习文档 函数可以有两个返回值 ...

  4. TCP/IP详解(包含ack,seq)

    前言 个人认为在web开发中,对于TCP/IP协议的理解是首当其冲的,在大多数框架的冲击下,使我们淡化了对于TCP/IP协议的理解. 理解好TCP/IP对于每个web开发者都是很有必要的. TCP/I ...

  5. Kettle日志中BootFeaturesInstaller错误

    到新公司接手了别人的Kettle ETL作业. 发现每次启动 Kettle ,日志中都会出现下面的错误,虽然不影响运行结果,但是看着不爽: 18:41:15,327 INFO [KarafInstan ...

  6. 轻量Pythonweb - flask+jinja2

    后台代码 MVC from flask import Flask,request,render_template app = Flask(__name__) @app.route('/',method ...

  7. OCC上下文设置显示模式

    #include <AIS_InteractiveContext.hxx> 通过AIS_InteractiveContext::SetDisplayMode()函数来设置 void  Se ...

  8. 半导体知识:蚀刻(Etch)工艺讲解

    本文转载自微信公众号 - 半导体行业观察  , https://mp.weixin.qq.com/s/F3LXiub6n4iYsQDqDH9K_g

  9. Android屏幕设置只允许上下旋转

    android:screenOrientation = ["unspecified" | "behind" |                          ...

  10. #0 scrapy爬虫学习中遇到的坑记录

    python 基础学习中对于scrapy的使用遇到了一些问题. 首先进行的是对Amazon.cn的检索结果页进行爬取,很顺利,无碍. 下一个目标是对baidu的搜索结果进行爬取 1,反爬虫 1.1 我 ...