下载此文档

数据库连接池详细说明.doc


文档分类:IT计算机 | 页数:约13页 举报非法文档有奖
1/13
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/13 下载此文档
文档列表 文档介绍
数据库连接池详细说明
首先建立个池子,里面放这我们需要的链接,党我们需要链接的时候从池子里面取,取的时候先判断是否有空闲的,有就拿来用,否则检查是否全用了,如果没有全用,则新建,否则等待或者异常抛出。
 假设我们要链接不同的数据库,把相关的配置写在一个xml文件,格式如下:
 。xml
 〈 ds—config〉 
 〈 pool〉 
 < type〉 mysql< /type> 
 〈 name> test< /name> 
 < driver〉 com。。driver〈 /driver〉 
 < url> jdbc:mysql://localhost:3306/test< /url> 
 〈 username〉 root〈 /username〉 
 〈 password> 123456< /password〉 
 〈 maxconn> 100< /maxconn> 
 < /pool> 
 < pool> 
 < type〉 mysql< /type> 
 〈 name> user2< /name> 
 < driver〉 com。mysql。jdbc。driver〈 /driver〉 
 〈 url〉 jdbc:mysql://localhost:3306/test〈 /url〉 
 < username> root< /username> 
 〈 password〉 123456〈 /password> 
 〈 maxconn〉 10< /maxconn> 
 〈 /pool〉 
 < /ds-config〉 
 然后我们建立个javabean来对应这个xml,
 
 package com。cgogo。dbpool 
 public class dsconfigbean {
 private string type = " ”   // 数据库类型
 private string name = " ”   // 连接池名字
 private string driver = ” "   // 数据库驱动
 private string url = " ”   // 数据库url
 private string username = " "   // 用户名
 private string password = ” "   // 密码
 private int maxconn = 0  // 最大连接数
 public dsconfigbean() {
     // todo auto-generated constructor stub
 }
 相关的set和get省略
 }
 
 接下来需要建立个池的类,来建立和释放链接
 
 package 。dbpool 
 import java。sql。connection 
 import java。 
 import 。sqlexception 
 import  
 import 。iterator 
 import java。util。timer 
 public class dbconnectionpool {
 private connection con = null 
 private int inused = 0  // 使用的连接数
 private arraylist freeconnections = new arraylist() // 容器,空闲连接
 private int minconn  // 最小连接数
 private int maxconn  // 最大连接
 private string name  // 连接池名字
 private string password  // 密码
 private string url  // 数据库连接地址
 private string driver  // 驱动
 private string user  // 用户名
 public timer timer  // 定时
 省略set和get
 public dbconnectionpool() {
 }
 public dbconnectionpool(string name  string driver  string url 
      string user 

数据库连接池详细说明 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数13
  • 收藏数0 收藏
  • 顶次数0
  • 上传人phl805
  • 文件大小31 KB
  • 时间2021-04-16