Database Change Notification
使用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的更多相关文章
- PIC32MZ tutorial -- Change Notification
In my last post I implement "Key Debounce" with port polling, port polling is not very eff ...
- 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 ...
- MongoDB Change Stream:简介、尝试与应用
在MongoDB3.6引入的新feature中,change stream无疑是非常吸引人的. Change streams allow applications to access real-tim ...
- iOS开发——OC篇&消息传递机制(KVO/NOtification/Block/代理/Target-Action)
iOS开发中消息传递机制(KVO/NOtification/Block/代理/Target-Action) 今晚看到了一篇好的文章,所以就搬过来了,方便自己以后学习 虽然这一期的主题是关于Fou ...
- Database(Mysql)发版控制二
author:skate time:2014/08/18 Database(Mysql)发版控制 The Liquibase Tool related Database 一.Installation ...
- Obtaining Directory Change Notifications(微软的例子,使用FindFirstChangeNotification,FindNextChangeNotification,FindCloseChangeNotification API函数)
An application can monitor the contents of a directory and its subdirectories by using change notifi ...
- CMU Database Systems - Embedded Database Logic
正常应用和数据库交互的过程是这样的, 其实我们也可以把部分应用逻辑放到DB端去执行,来提升效率 User-defined Function Stored Procedures Triggers Cha ...
- PHP7函数大全(4553个函数)
转载来自: http://www.infocool.net/kb/PHP/201607/168683.html a 函数 说明 abs 绝对值 acos 反余弦 acosh 反双曲余弦 addcsla ...
- Microsoft Win32 to Microsoft .NET Framework API Map
Microsoft Win32 to Microsoft .NET Framework API Map .NET Development (General) Technical Articles ...
随机推荐
- redis-cli 通过管道 --pipe 快速导入数据到redis中
最近有个需求,需要把五千万条数据批量写入redis中,方法倒是有很多种!效率最高的就是通过redis-cl管道的方式写入 一:先看看命令 cat redis.txt | redis-cli -h 12 ...
- <知识整理>2019清北学堂提高储备D1
一.枚举: 枚举是最简单最基础的算法,核心思想是将可能的结果都列举出来并判断是否是解. 优点:思维简单,帮助理解问题.找规律.没头绪时 缺点:时空复杂度较高,会有很多冗余的非解(简单的枚举几乎没有利用 ...
- jupyter nootbook本地使用指南
本地文件读入jupyter notebook 在文件夹内,shift+鼠标右键,出现菜单中选择“”在此处打开命令窗口“”,输入jupyter notebook, 可以把本地文件读入jupyter.
- Jmeter工具进行一个完整的接口测试
Jmeter工具进行一个完整的接口测试 1.创建一个线程组 通俗的讲一个线程组,,可以看做一个虚拟用户组,线程组中的每个线程都可以理解为一个虚拟用户. 2.输入线程组名字 3.添加一个cookie ...
- JavaScript传递参数方法
1.SetTimer传递参数 setTimeout(function (obj) { obj.myScroll = new IScroll('#wrapper', { click: true }); ...
- STM32库函数void USART_SendData的缺陷和解决方法
void USART_SendData()函数在快速发送时存在问题 有丢数据的可能 转自https://blog.csdn.net/qq_27114397/article/details/506015 ...
- mysql数据库 表 导入导出
1.导出表结构 mysqldump --no-data -h192.168.222.11 -uroot -proot --databases db01 db02 db30>file.sql 2. ...
- 基于Spring注解搭建SpringMVC项目
在2018寒冬,我下岗了,因为我的左脚先迈进了公司的大门.这不是重点,重点是我扑到了老板小姨子的怀里. 网上好多教程都是基于XML的SpringMVC,想找一篇注解的,但是写的很模糊,我刚好学到这里, ...
- MySQL2.字符集乱码
MySQL2.字符集 此节记录下MySQL出现乱码的原因.还是参考小册子~ 字符集简介 计算机中只能存储二进制数据,建立字符与二进制数据的映射关系来存储字符. 从两方面考虑: 1.界定清楚字符范围,即 ...
- RNN回归
import torch from torch import nn import numpy as np import matplotlib.pyplot as plt # torch.manual_ ...