tomcat6 实现连接池两种方法 (通过测试)

方案一:c3p0实现

1> 在tomcat\conf\server.xml的GlobalNamingResources中增加:

 <Resource auth="Container"
    description="DB Connection"
    driverClass="com.mysql.jdbc.Driver"
    maxPoolSize="10"
    minPoolSize="2"
    acquireIncrement="2"
    name="jdbc/mldn"
    user="root"
    password="root"
    factory="org.apache.naming.factory.BeanFactory"
    type="com.mchange.v2.c3p0.ComboPooledDataSource"
    jdbcUrl="jdbc:mysql://localhost:3307/mldn?autoReconnect=true" />

2> 在tomcat\conf\context.xml的Context中增加:  

<ResourceLink name="jdbc/mldnl" global="jdbc/mldn" type="javax.sql.DataSource"/>

3> 在web.xml中增加: 

  <resource-ref>
     <description>DB Connection</description>
     <res-ref-name>jdbc/mldn</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
  </resource-ref>

方案二:dbcp普通实现

1> 在tomcat\conf\server.xml的GlobalNamingResources中增加:

   <Resource name="jdbc/mldn"
                  auth="Container"
                  type="javax.sql.DataSource"
                  driverClassName="org.gjt.mm.mysql.Driver"
                  url="jdbc:mysql://localhost:3307/mldn"
                  username="root"          
                  password="root"
                  maxActive="100"
                  maxIdle="30"             
                  maxWait="10000"
                  factory="org.apache.commons.dbcp.BasicDataSourceFactory"                             
                 />

 

2> 在tomcat\conf\context.xml的Context中增加:  

<ResourceLink name="jdbc/mldnl" global="jdbc/mldn" type="javax.sql.DataSource"/>

3> 在web.xml中增加: 

  <resource-ref>
     <description>DB Connection</description>
     <res-ref-name>jdbc/mldn</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
  </resource-ref>

posted @ 2008-11-24 16:45  奋斗蟹  阅读(798)  评论(0编辑  收藏  举报