电脑教程中文网
首页  动态网站建设学习 程序  笑话  论坛 娱乐  交友 ADSL  峄城  成功者
中文名:电脑教程中文网,收集了大量的电脑教程! 编程技术文档 游戏开发 笑话站暂时关闭 设为首页
网页设计 HTML | Dreamweaver | CSS | Firework | FrontPage WEB开发 ASP | JSP | PHP | .NET | CGI | JS | VBS | XML | IIS6 | Apache | PWS
程序设计 Java | C++ |VC++ | C# | Delphi | VB | C语言 | 汇编 | Pascal | Perl 数据库 MSSQL | MySQL | Access | VF | Oracle | DB2 | SYBASE |
办公软件 Word | Excel | WPS | PowerPoint 动画平面 Photoshop | ACDSee | 3Dmax | Flash | Coreldraw |
操作系统 Windows 2000 | Windows XP | Windows 2003 | SCO Unix | Windows Vista | unix、Linux | 综合| 服务器 | 系统安全| 黑客技术
其  他 UltraDev | DOS | UML | PWS | Powerbuilder | 开发心得 | 设计理念 | 病毒库 | 其他 | LightTPD (分类排序给您带来不便请谅解)
推  荐: Java文档500篇》《ASP.NET与相关数据库技术高级指南》《TC图形函数详解》《C函数速查手册》《C语言编程宝典之一》《MFC深入浅出》《黑客零起点》《VC++ 编程指南》《JScript 用户指南》 《CSS教程宝典》《Microsoft Jet SQL 参考》《delphi技巧集合》《MySQL 4.1.0 中文参考手册》《MySQL中文手册
【导航】 您现在的位置 : 首页 - database教程 - 《Oracle数据库技术文档-收集》- 利用Oracle自带的连接池类的一例

利用Oracle自带的连接池类的一例

日期:2005-8-5 17:19:19    作者:佚名   人气:   来源:网络





 
/**
封装了对数据库的连接,用于处理SQL语句。
@author:yancheng(sharetop studio)
@version:1.0.0
*/
package DBUtil;

import java.sql.*;
import java.io.*;
import javax.sql.*;
import javax.naming.*;
import oracle.jdbc.pool.*;

public class OraPooledSQL
{

private PooledConnection dbpool;

/**
@param ConnectionURL 连接名 如: jdbc:odbc:myODBC
@param UserID 用户名
@param PassWord 用户密码
*/
public OraPooledSQL(String ConnectionURL,String UserID,String PassWord)
{

try{

OracleConnectionPoolDataSource ocpds = new OracleConnectionPoolDataSource();

ocpds.setURL(ConnectionURL);

ocpds.setUser(UserID);

ocpds.setPassword(PassWord);

dbpool = ocpds.getPooledConnection();

}
catch(Exception ex)
{
System.err.println("Error in PooledSQL-construct : ");
ex.printStackTrace(System.err);
}

}//end OraPooledSQL

//close dbpool
protected void finalize()
{
if( dbpool != null )
{
try
{
dbpool.close();
}
catch(Exception ex)
{
}
}
}

/**
用于更新、添加或删除的SQL语句
@param SQL SQL语句字串,如:insert into tablename values(id,......)
*/
public int Update(String SQL)
{
Statement stmt = null;
int rc = 0;

Connection connection = null;

try
{
connection = dbpool.getConnection();
stmt = connection.createStatement();
rc = stmt.executeUpdate(SQL);
}

catch( Exception ex )
{
System.err.println("Error in Update - OraPooledSQL : ");
ex.printStackTrace(System.err);
}

return rc;

} //end Update()

/**
用于查询的SQL语句
@param SQL SQL语句字串,如:select * from tablename
*/
public ResultSet Query(String SQL)
{
Statement stmt = null;
ResultSet rs = null;
Connection connection = null;

try
{
connection = dbpool.getConnection();
stmt = connection.createStatement();
rs = stmt.executeQuery(SQL);
}

catch( Exception ex )
{
System.err.println("Error in Query - SQLBean : ");
ex.printStackTrace(System.err);
}

return rs;

} //end Query

} //end Class

  <




网站首页 - 友情链接 - 公司简介 - 联系方式 - 广告投放 - 客户服务 - 错误报告 - 免责声明 - About us
CLDE.NET电脑教程中文网版权所有 未经许可禁止镜象和复制本站资料 MSN:CLDE_NET@hotmail.com
技术支持:CLDE.NET信息中心 鲁ICP备05039940号 友情链接QQ:784079(隐)