用proxool配置数据库连接池步骤

   1、下载proxool 地址: http://proxool.sourceforge.net/download.html
    2、解压缩proxool-0.9.0RC2.zip,拷贝lib/proxool-0.9.0RC2.jar到web-info/lib
       拷贝jdbc驱动到web-info/lib
    3、在web-info下建立文件:proxool.xml
     文件内容如下:
<? xml version="1.0" encoding="ISO-8859-1" ?>
< something-else-entirely >  
< proxool >     
    
< alias > kc </ alias >     
     
< driver-url > jdbc:microsoft:sqlserver://jifeng:1433;databasename=yao; </ driver-url >  
    
<!-- <driver-url>jdbc:microsoft:sqlserver://localhost:1433;databasename=kc;</driver-url> -->
    
< driver-class > com.microsoft.jdbc.sqlserver.SQLServerDriver </ driver-class >     
    
< driver-properties >       
        
< property  name ="user"  value ="sa" />       
        
< property  name ="password"  value ="" />     
    
</ driver-properties >     
    
< maximum-connection-count > 10 </ maximum-connection-count >
    
< house-keeping-test-sql > select CURRENT_DATE </ house-keeping-test-sql >             
</ proxool >
</ something-else-entirely >

    4、在web.xml文件内加入以下内容:

     < servlet >
        
< servlet-name > ServletConfigurator </ servlet-name >
          
< servlet-class > org.logicalcobwebs.proxool.configuration.ServletConfigurator </ servlet-class >
          
< init-param >
            
< param-name > xmlFile </ param-name >
            
< param-value > WEB-INF/proxool.xml </ param-value >
          
</ init-param >
          
< load-on-startup > 1 </ load-on-startup >
    
</ servlet >

<!-- proxool提供的管理监控工具,可查看当前数据库连接情况。如果运行不成功,请删除本行 -->
 
     < servlet >
          
< servlet-name > Admin </ servlet-name >
          
< servlet-class > org.logicalcobwebs.proxool.admin.servlet.AdminServlet </ servlet-class >
    
</ servlet >
                                                                               
    
< servlet-mapping >
          
< servlet-name > Admin </ servlet-name >
          
< url-pattern > /admin </ url-pattern >
    
</ servlet-mapping >


     5、在调用数据库连接代码:
import  java.sql. * ;
import  javax.sql. * ;
import  javax.naming. * ;
import  org.logicalcobwebs.proxool.configuration. * ;

public   class  Pool
{
     
/**
     * 得到数据库的连接.
     * 
@throws Exception Pool:getConnection()--连接池获得连接出错
     
*/

     
public static Connection getConnection() throws Exception
    
{
        
//Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
        
//PropertyConfigurator.configure("proxool.properties");
        
//JAXPConfigurator.configure("proxool.xml", false); 
        try
        
{
            Connection conn 
= DriverManager.getConnection("proxool.kc");
            
return conn;
        }

        
catch(Exception e)
        
{
            
throw new Exception("Pool:getConnection()--连接池获得连接出错,请才web.xml文件中配置初始化参数。"+e.getMessage());
        }
        
    }
 
}


     6、利用proxool监控工具查看数据库运行状态。地址:./admin
 

你可能感兴趣的:(exception,servlet,数据库连接池,Microsoft,sqlserver,import)