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 ...
随机推荐
- Vue针对性笔记
Github原文阅读 MVVM(Model-View-ViewModel)模型 MVVM分为Model.View.ViewModel三部分. Model代表数据模型,定义数据和业务逻辑,访问数据层 V ...
- 快速理解js中的call,apply的作用
今天被人问到js中的call,apply的区别和用途,解释了一番后,想到之前在逼乎上看到一位小伙伴生动形象的解释 本身不难理解,看下MDN就知道了,但是不常用,遇到了,还要脑回路回转下.或者时间长了, ...
- dsu on tree 树上启发式合并 学习笔记
近几天跟着dreagonm大佬学习了\(dsu\ on\ tree\),来总结一下: \(dsu\ on\ tree\),也就是树上启发式合并,是用来处理一类离线的树上询问问题(比如子树内的颜色种数) ...
- 第四十四篇--做一个简单的QQ登录界面
功能:输入用户名和密码,正确,显示登录成功,为空的话,提示用户名和密码不能为空,还有记住密码功能. MainActivity.java package com.aimee.android.play.q ...
- uninitialized_copy()效果试验
根据<STL源码剖析>这段节选描述,实现如下代码进行测试 #include "2jjalloca.h" #include <vector> #include ...
- IDEA 常用配置
调节代码字体大小 设置:File --- Settings... --- Editor --- General --- 勾选Change font size(Zoom) with Ctrl + Mou ...
- redis connection refused: connect 启动失败
先到redis解压包下执行 ./redis-server redis.conf 再连接 redis-cli
- 多输入select
目录 多输入select IO模型 select介绍 小demo 注意 引入电子书 title: 多输入select date: 2019/3/20 17:21:34 toc: true --- 多输 ...
- linux 命令之文件读取,head, tail, tailf, sed
head 看文件的前100行head -100 filename tail/tailf查看文件的后100行tail -100 filename 或 tail -n 100 filename ta ...
- 初识正则表达式matcher.group
matcher.group中group是匹配()的,group(0)指的是整个串,group(1) 指的是第一个括号里的内容,group(2)指的第二个括号里的内容,以此类推. 例如: str = & ...