- 浏览: 111764 次
- 性别:
- 来自: 北京
文章分类
最新评论
oracle dcn(data change notification)
当数据库中数据改变时发出通知,可以在sql级pl_sql中设置监听
package test;
import java.sql.*;
import java.util.Properties;
import oracle.jdbc.*;
import oracle.jdbc.dcn.*;
public class DBChangeNotification {
static final String USERNAME = "jc608031";
static final String PASSWORD = "jc608031";
static String URL = "jdbc:oracle:thin:@192.168.1.246:1521:jcs";
public static void main(String[] argv) {
DBChangeNotification demo = new DBChangeNotification();
try {
demo.run();
} catch (SQLException mainSQLException) {
mainSQLException.printStackTrace();
}
}
void run() throws SQLException {
OracleConnection conn = connect();
// first step: create a registration on the server:
Properties prop = new Properties();
// if connected through the VPN, you need to provide the TCP address of
// the client.
// For example:
// prop.setProperty(OracleConnection.NTF_LOCAL_HOST,"14.14.13.12");
// Ask the server to send the ROWIDs as part of the DCN events (small
// performance
// cost):
// prop.setProperty(OracleConnection.DCN_NOTIFY_ROWIDS, "true");
//
// Set the DCN_QUERY_CHANGE_NOTIFICATION option for query registration
// with finer granularity.
prop.setProperty(OracleConnection.DCN_NOTIFY_ROWIDS, "true");
prop.setProperty(OracleConnection.DCN_IGNORE_DELETEOP, "true");
// prop.setProperty(OracleConnection.NTF_TIMEOUT, "3600");
// The following operation does a roundtrip to the database to create a
// new
// registration for DCN. It sends the client address (ip address and
// port) that
// the server will use to connect to the client and send the
// notification
// when necessary. Note that for now the registration is empty (we
// haven't registered
// any table). This also opens a new thread in the drivers. This thread
// will be
// dedicated to DCN (accept connection to the server and dispatch the
// events to
// the listeners).
DatabaseChangeRegistration dcr = conn
.registerDatabaseChangeNotification(prop);
try {
// add the listenerr:
dcr.addListener(new DatabaseChangeListener() {
@Override
public void onDatabaseChangeNotification(DatabaseChangeEvent e) {
// TODO Auto-generated method stub
DatabaseChangeEvent.EventType etype = e.getEventType();
System.out.println("receive " + etype + " event, RegId="
+ e.getRegId());
}
});
conn.setAutoCommit(true);
String sql = "update mytest set name=? where id = 'w'";
PreparedStatement upPstmt = conn.prepareStatement(sql);
upPstmt.setString(1, "aa");
upPstmt.executeUpdate();
} catch (SQLException ex) {
// if an exception occurs, we need to close the registration in
// order
// to interrupt the thread otherwise it will be hanging around.
if (conn != null)
conn.unregisterDatabaseChangeNotification(dcr);
throw ex;
} finally {
try {
// Note that we close the connection!
conn.close();
} catch (Exception innerex) {
innerex.printStackTrace();
}
}
}
/**
* Creates a connection the database.
*/
OracleConnection connect() throws SQLException {
OracleDriver dr = new OracleDriver();
Properties prop = new Properties();
prop.setProperty("user", DBChangeNotification.USERNAME);
prop.setProperty("password", DBChangeNotification.PASSWORD);
Connection conn = dr.connect(DBChangeNotification.URL, prop);
OracleConnection oconn = (OracleConnection) conn
.unwrap(OracleConnection.class);
return oconn;
}
}
发表评论
-
Google公开Megastore论文——解决NoSQL、SQL融合难题
2011-03-02 14:44 639实际上,作为一个建 ... -
开源数据库Sharding技术
2011-03-02 16:14 685内容摘要:Sharding 不是一个某个特定数据库软件附 ... -
Java 开发 2.0: 使用 Hibernate Shards 进行切分
2011-03-02 16:26 614当关系数据库试图在 ... -
可扩展的分布式数据库架构
2011-03-03 14:44 660本文发表在《程序员 ... -
OLTP系统与DSS系统对比
2011-03-03 15:35 614在进行数据库系统的设计时,一个不可忽视的问题是弄清你所 ... -
Oracle高级复制机制
2011-03-10 15:48 635Oracle高级复制即可支 ... -
Oracle高级复制的同步复制的配置步骤说明
2011-03-10 15:50 808以下的文章主要讲述的是Oracle高级复制的同步复制,如 ... -
linux oracle中文乱码问题解决方法
2011-04-11 15:18 674connect system/oracle9i ... -
ubuntu下安装ocfs2
2011-07-12 14:20 942简介 一个集群文件系统能使运行在集群中所有节点并发的通过 ... -
asm下载地址
2011-07-12 16:50 802asm rpm包下载地址http://www.oracle.c ... -
oracle重要初始参数
2011-09-28 17:15 845OPEN_CURSORS session可以打开的游标最大数, ... -
SQLJ是什么?优点?
2011-10-11 09:56 879SQLJ是一种允许把静态的SQL语句以文本形式嵌入Java程序 ... -
共享池的调整与优化(Shared pool Tuning)
2011-10-11 10:53 711共享池(Shared pool)是SGA中最关键的内存片段,共 ... -
使用DBMS_SHARED_POOL包将PL/SQL大对象保存到Shared Pool
2011-10-11 16:32 703当系统在加载PL/SQL大对象时,有可能遭遇由于SharedP ... -
oracle sga相关
2011-10-12 17:08 813oracle主要影响性能的内存: Shared ... -
oracle内存调整相关
2011-10-14 15:52 866db_cache_size与sga_target关系 db_ ... -
oracle索引分类
2011-10-17 13:31 819B-TREE INDEX,B树索引:在创建索引时他是 ... -
修改oracle redo log的大小
2011-10-17 15:53 10561.查看现在的REDO GRO ... -
本地管理表空间
2011-10-18 13:29 732本地管理表空间的好处: 1:快速,并发空间操作 ... -
Oracle表空间命令
2011-10-19 16:55 770创建立表空间 CREATE TABLESPACE ...
相关推荐
基于Oracle DCN的缓存一致性技术.pdf
oracle机制及内存区的优化建议,主要是为了我的积分,实在没办法,感激
oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料oracle资料
Oracle 9i Client (Oracle 9i 客户端) 简化版 (不安装Oracle客户端,也可以使用PLSQL Developer 不用安装Oracle客户端也可以使用PLSQL Developer 绿色! 安全! 轻便! 可靠! 1、本软件可作为简单的Oracle9i客户端...
Dbmover for Mysql to Oracle 是高效的将Mysql导入到Oracle数据库的工具。 使用DBMover可以灵活定义Mysql和Oracle之间表和字段的对照关系,也可以在DBMover创建一个查询,把查询结果当作源表转入到Oracle中。 ...
Oracle详解Oracle详解Oracle详解Oracle详解
oracle 通知服务(DCN) oracle data change notification,可用
python-oracledb的源码和使用示例代码, python-oracledb 1.0,适用于Python versions 3.6 through 3.10. Oracle Database; This directory contains samples for python-oracledb. 1. The schemas and SQL ...
oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件oracle_课件
使用了,ODP.NET 方式链接数据库,只要把Oracle.ManagedDataAccess.dll引入取代以前的Oracle.DataAccess.dll即可。 这种方式也是oracle公司提供的,稳定性要比之前那种更好,而且也是免安装客户端的,目前还没测试...
oracle 9i所有版本最新下载链接 直接迅雷下载 Oracle9i Database Release 2 Enterprise/Standard/Personal Edition for Windows NT/2000/XP ...
Oracle Instant Client 11.2.0.1.0是轻量级Oracle客户端,用于连接访问Oracle 9i、10g、11g 11.2.0.1.0版本的Oracle数据库。 Oracle Instant Client11.2.0.1.0 安装程序包含OCI/ OCCI、JDBC-OCI SDK(软件开发工具...
oracle 数据库oracle 数据库oracle 数据库oracle 数据库oracle 数据库oracle 数据库oracle 数据库
oracle oracle oracle oracle
ORACLE资料ORACLE资料ORACLE资料ORACLE资料ORACLE资料
oracle心得oracle心得oracle心得oracle心得oracle心得
Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典Oracle宝典...
ORACLE数据库ORACLE数据库ORACLE数据库ORACLE数据库ORACLE数据库ORACLE数据库ORACLE数据库ORACLE数据库
ORACLE分区ORACLE分区ORACLE分区ORACLE分区ORACLE分区ORACLE分区ORACLE分区ORACLE分区ORACLE分区ORACLE分区ORACLE分区ORACLE分区ORACLE分区ORACLE分区
oracle 闪回oracle 闪回oracle 闪回oracle 闪回oracle 闪回oracle 闪回oracle 闪回oracle 闪回oracle 闪回oracle 闪回oracle 闪回oracle 闪回oracle 闪回oracle 闪回