此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【wzcyd】截止到2008-07-22 15:55:04的历史汇总数据(不包括此帖):
发帖的总数量:8                        发帖的总分数:560                      每贴平均分数:70                       
回帖的总数量:14                       得分贴总数量:2                        回帖的得分率:14%                      
结贴的总数量:6                        结贴的总分数:450                      
无满意结贴数:0                        无满意结贴分:0                        
未结的帖子数:2                        未结的总分数:110                      
结贴的百分比:75.00 %               结分的百分比:80.36 %                  
无满意结贴率:0.00  %               无满意结分率:0.00  %                  
楼主加油

解决方案 »

  1.   

    代码自己优化好了哪位有jdbc连接池的代码?
      

  2.   

    你是bs还是cs的呀
    bs的直接在容器配 就可以了
    cs的就麻烦点了
      

  3.   

    网上有很多
    拿一个改一下就可以用了package e_office.systemframework.pool;
    /**
    *编者:李国庆
    *类的描述信息:此类为一个数据库连接池类,是一个单态的类,其中对数据库连接的信息
    *都放在一个属性文件中,可以进行方便的设置***
    *最后修改时间:2006-1-12 10:30*********
    */
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.ResourceBundle;/**
     * 这是一个数据库连接池
     *访问属性文件:mypool.properties
     *返回一个Connection
     *
     */
     
    public class ConnectionPool{
     private int minConn;        //最少连接数
     private int maxConn;        //最大连接数
     private String user;        //用户名
     private String password;    //数据库密码
     private int connAmount;       //现有连接个数
     private Stack connStack;     //使用Stack保存数据库连接
     private String dry;            //驱动
     private String connString;    //连接字符串  
     private static ConnectionPool  connectionPool;
     private int waitTime;               //忙时的等告待时间
     static ResourceBundle  bundle=null;    //属性文件读取
     
     
     
     /**
      *返回一个实例。如果是第一次调用此方法则个建一个实例
      */
      public static  synchronized ConnectionPool getInstance(){
       if(connectionPool==null){
        connectionPool = new ConnectionPool();
       }
       return connectionPool;
      }
     
     /**
      *读属性文件得到数据库连接信息及连接池信息
      */
      public void readProperties(){
        
       try
       {
        bundle=ResourceBundle.getBundle("properties.mypool");
        this.user=bundle.getString("user");
        this.password = bundle.getString("password");
        this.connString=bundle.getString("connString");
        this.dry = bundle.getString("dry");
       
        this.minConn=Integer.parseInt(bundle.getString("minConn"));
        System.out.println("this  mincon:"+this.minConn);
        this.maxConn=Integer.parseInt(bundle.getString("maxConn"));
        this.waitTime=Integer.parseInt(bundle.getString("waitTime"));
            
       }
       catch(Exception w) { w.toString();  }
       System.out.println("初始化成功..........");
       
      }
     
      private ConnectionPool(){
       readProperties();
       this.connStack = new Stack();
       System.out.println(this.dry);
       try{
        Class.forName(this.dry);
       }catch(Exception e){
        e.printStackTrace();
       }
       for(int i = 0;i<this.minConn;i++){
        System.out.println("myPool:"+i);
        connStack.push(newConnection());
       }
      }
     
      /**
       *从连接池得到连接
       */
       public synchronized Connection getConnection(){
        Connection conn = null;
        System.out.println("user connection:"+this.connStack.size());
        if(!this.connStack.empty()){
         conn = (Connection)connStack.pop();
         System.out.println("得到一个连接");
        }else if(this.connAmount<this.maxConn){
         conn = newConnection();
        }else{
         try{
          wait(this.waitTime);
          System.out.println("等待");
          return getConnection();
         }catch(Exception e){
          e.printStackTrace();
         }
        }
        return conn;
       }
      
       /**
        /*释放连接
        */
        public synchronized void freeConnection(Connection con){
         this.connStack.push(con);
         System.out.println("归还连接");
         notifyAll();
        }
     
     
      /**
       *创建新连接
       */
       public Connection newConnection(){
        Connection conn=null;
        try{
        
         conn = DriverManager.getConnection(this.connString,this.user,this.password);
         this.connAmount++;
         System.out.println("连接池创建一个连接"+conn.toString());
         return conn;
        }catch(Exception e){
         e.printStackTrace();
         return null;
        }
       }}
      

  4.   

    properties.mypool 文件也贴出来呀,还有怎么调用,连接池没弄过,所以还有点不清楚
      

  5.   

    你想做什么,配连接池吗?
    你的server用的什么?大部分都支持连接池配置 不用自己做