oracle自带示例,利用Oracle自带的连接缓冲类的一个例子.-JSP教程,资料/其它

import java.sql.connection;

import oracle.jdbc.pool.oracleconnectioncacheimpl;

/**

* 连接池管理类

*/

public class dbpool {

/** 连接池 */

private static oracleconnectioncacheimpl pool = null;

/**

* 初始化连接池

*/

public static void init() {

try{

string user = "user";                   //用户名

string password = "pwd";          //密码

string host = "127.0.0.1";          //server地址

string port = "1521";                 //端口

string sid = "oracle92";              //sid

int max = 20;                             //最大连接数

int min = 5;                                //最小连接数

//拼连接字符串

string url = "jdbc:oracle:thin:@" + host + ":" + port + ":" + sid;

//实例化连接池并设置参数

pool = new oracleconnectioncacheimpl();

pool.seturl(url);

pool.setpassword(password);

pool.setuser(user);

pool.setmaxlimit(max);

pool.setminlimit(min);

/**

* 设置连接数超限时增加方式.

* dynamic_scheme:是动态增加.用完如果超过上限则关掉.

* 还有两个.1.直接返回null .2.始终等待

*/

pool.setcachescheme(oracleconnectioncacheimpl.dynamic_scheme);

/**

* 如果你已经有个连接池了.

* 比如是oracleconnectionpooldatasource ocpds;

* 可以直接设置.前面的设置就不用了.或者直接写在构造器里.

*/

//pool.setconnectionpooldatasource(ocpds);

}catch(exception ex) {

}

}

/**

* 终了处理.

* 比如在app关掉前调用.

*/

public static void destory() {

if(pool != null) {

try {

pool.close();

pool = null;

}catch(exception ex) {

}

}

}

/**

* 取连接.

* 和其他的连接一样正常用.

* @return 连接

*/

public static connection getconnection() {

try{

connection conn = pool.getconnection();

return conn;

}catch(exception e){

return null;

}

}

/**

* 调试

*/

public static void turnning() {

system.out.println("active conns:"+pool.getactivesize());

system.out.println("cached conns:"+pool.getcachesize());

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值