日期:2014-05-16  浏览次数:20527 次

tomcat的数据库连接池(方法一)
这种方法麻烦一点,作用全局



1.server.xml

<GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
 
<Resource auth="Container"
     description="DB Connection"
     driverClass="com.mysql.jdbc.Driver"
     maxPoolSize="10"
     minPoolSize="2"
     acquireIncrement="2"
     name="jdbc/connPool"
     user="root"
     password="root"
     factory="org.apache.naming.factory.BeanFactory"
     type="com.mchange.v2.c3p0.ComboPooledDataSource"
     jdbcUrl="jdbc:mysql://localhost:3306/xinnuo?autoReconnect=true" />
</GlobalNamingResources>


2.context.xml
<ResourceLink name="jdbc/connPool" global="jdbc/connPool" type="javax.sql.DataSource"/>


3.web.xml(是tomcat的,而不是项目的)
<resource-ref>
     <description>DB Connection</description>
     <res-ref-name>jdbc/connPool</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
   </resource-ref>


注意jdbc/connPool这个名字是在3个是一样的