Spring2.5配置proxool连接池

来源:互联网 发布:查看linux系统编码格式 编辑:程序博客网 时间:2024/05/29 19:09

首先按正常步骤配置好proxool连接池,在web.xml中配置自动监控,做简单测试保证该连接池能够正常工作。proxool.xml配置如下:

1.proxool.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- the proxool configuration can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->
<something-else-entirely>
  <proxool>
    <alias>MyPool</alias>
    <driver-url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test;SelectMethod=cursor</driver-url>
    <driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
    <driver-properties>
      <property name="user" value="testuser"/>
      <property name="password" value="testpwd"/>
    </driver-properties>
    <maximum-connection-count>80</maximum-connection-count>
    <minimum-connection-count>20</minimum-connection-count>
    <house-keeping-sleep-time>180000</house-keeping-sleep-time>
    <prototype-count>5</prototype-count>
    <house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
  </proxool>
</something-else-entirely>
 

2.applicationContext.xml配置proxool连接池,有两种方式,一种是利用上面配置好的proxool.xml文件,另一种方式是直接在applicationContext.xml中配置,首先看方式一:

   <bean   id="TestSource"   class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
          <property   name="driverClassName">  
              <value>org.logicalcobwebs.proxool.ProxoolDriver</value>  
          </property>  
          <property   name="url">  
              <value>proxool.MyPool</value>   <!--proxool是proxool.xml的文件名,MyPool是proxool.xml中配置的别名-->
          </property>  
   </bean>  

方式二:(根据网友资料整理)

<bean id="MyDataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource" destroy-method="close">
    <property name="driver">
      <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
    </property>
    <property name="driverUrl">
      <value>jdbc:microsoft:sqlserver://localhost:1433;user=test;password=test;DatabaseName=test;SelectMethod=cursor</value>    
    </property>
    <property name="user"> <!-- 必须在这里也设置,但是 proxool却不使用它,或许是个bug-->
      <value>test</value>
    </property>
    <property name="password"> <!-- 必须在这里也设置,但是 proxool却不使用它,或许是个bug-->
      <value>test</value>
    </property>

    <property name="alias">
      <value>MyPool</value>
    </property>
    <property name="houseKeepingSleepTime">
      <value>90000</value>
    </property>
    <property name="prototypeCount">
      <value>5</value>
    </property>
    <property name="maximumConnectionCount">
      <value>100</value>
    </property>
    <property name="minimumConnectionCount">
      <value>10</value>
    </property>
    <property name="trace">
      <value>true</value>
    </property>
    <property name="verbose">
      <value>true</value>
    </property>
  </bean>

 

在Strut2中做简单测试,利用JdbcTemplate来查询:

  final List resourceList= new ArrayList();
  ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
  DataSource ds =(DataSource) ctx.getBean("TestSource");
  JdbcTemplate jdbcTemplate=new JdbcTemplate(ds);
  jdbcTemplate.query("select * from 资源预约表", new RowCallbackHandler(){
   public void processRow(ResultSet rs) throws SQLException{
    Map user=new HashMap();
    user.put("username", rs.getString("reg_content"));
    user.put("xq",rs.getString("reg_xq"));
    resourceList.add(user);
   }
  });

原创粉丝点击