heting

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            40 隨筆 :: 9 文章 :: 45 評論 :: 0 Trackbacks
          public class Pools extends HttpServlet {
           
           
          private static final long serialVersionUID = 1L;
           
           
          public static BasicDataSource bds = new BasicDataSource();

           
          public static ConnectionFactory fac = null;

           
          public synchronized static Connection getDSConn() {
            Pools aa
          =new Pools();
            
          try {
             aa.init();
            }
           catch (ServletException e1) {
             e1.printStackTrace();
            }

            Connection conn 
          = null;
            
          try {
             conn 
          = fac.createConnection();
            }
           catch (Exception e) {
             System.out.println(
          "fac.createConnection()"+e.toString());
            }

            
          return conn;
           }


           
          public void init(ServletConfig conf) throws ServletException {
           
          //super.init(conf);
            try {
             
             bds.setDriverClassName(
          "com.microsoft.jdbc.sqlserver.SQLServerDriver");
             bds.setUrl(
          "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=dbname");

             bds.setUsername(
          "sa");  

             bds.setPassword(
          "1234"); 

             bds.setInitialSize(
          100); 
             bds.setMaxActive(
          2);     
             bds.setMaxIdle(
          10); 

             bds.setMaxWait(
          1000 * 60); 

             fac 
          = new DataSourceConnectionFactory(bds);
             System.out.println(
          ">>>>init success>>>>");
            }
           catch (Exception e) {
             e.printStackTrace();
            }

           }


           
          public void destory() throws SQLException {
            bds.close();
            bds
          =null;
            fac
          =null;
           }


          }



          在web.xml中添加Pools配置信息

           

          <servlet>
            
          <servlet-name>Pools</servlet-name>
            
          <servlet-class>dbconn.Pools</servlet-class>
            
          <load-on-startup>1</load-on-startup>
           
          </servlet>

          可以將配置連接池的一些參數(shù)寫在web.xml中,實現(xiàn)可配置的連接池

          posted on 2009-03-04 11:09 賀挺 閱讀(182) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 大兴区| 凤翔县| 视频| 晴隆县| 深州市| 连江县| 丹东市| 齐齐哈尔市| 绵竹市| 毕节市| 龙门县| 长汀县| 赤峰市| 镇安县| 仙游县| 毕节市| 民县| 浮山县| 安多县| 芜湖市| 马龙县| 榆树市| 平度市| 淳化县| 二手房| 临安市| 临清市| 威远县| 万山特区| 顺义区| 黔西| 新晃| 宣武区| 成安县| 临洮县| 都匀市| 郁南县| 临安市| 图木舒克市| 榕江县| 肇东市|