登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

清风幻影的博客

Where there is love, I will be there.

 
 
 

日志

 
 
关于我

同是天涯沦落人,相逢何必曾相识. 天生我材必有用,千金散尽还复来. 天若有情天亦老,人间正道是沧桑. 月影西斜人已去, 堤上梅花情依旧, 此情故已成追忆, 美人如玉夜留香

在tomcat与jboss中配置c3p0连接池  

2009-12-14 10:05:24|  分类: jboss资料 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |


Appendix D: Configuring c3p0 DataSources in TomcatGo To Top

You can easily configure Apache's Tomcat web application server to use c3p0 pooled DataSources. Below is a Tomcat 5.0 sample config to get you started. It's a fragment of Tomcat's conf/server.xml file, which should be modified to suit and placed inside a <Context> element.


<Resource name="jdbc/pooledDS" auth="Container" type="com.mchange.v2.c3p0.ComboPooledDataSource" /> <ResourceParams name="jdbc/pooledDS"> <parameter> <name>factory</name> <value>org.apache.naming.factory.BeanFactory</value> </parameter> <parameter> <name>driverClass</name> <value>org.postgresql.Driver</value> </parameter> <parameter> <name>jdbcUrl</name> <value>jdbc:postgresql://localhost/c3p0-test</value> </parameter> <parameter> <name>user</name> <value>swaldman</value> </parameter> <parameter> <name>password</name> <value>test</value> </parameter> <parameter> <name>minPoolSize</name> <value>5</value> </parameter> <parameter> <name>maxPoolSize</name> <value>15</value> </parameter> <parameter> <name>acquireIncrement</name> <value>5</value> </parameter> </ResourceParams>

For Tomcat 5.5, try something like the following (thanks to Carl F. Hall for the sample!):


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

The rest is standard J2EE stuff: You'll need to declare your DataSource reference in your web.xml file:

<resource-ref> <res-ref-name>jdbc/pooledDS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>

And you can access your DataSource from code within your web application like this:

InitialContext ic = new InitialContext(); DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/pooledDS");

That's it!


拷贝jdbc.jar和c3p0.jar到defaul/lib/下

Appendix E: JBoss-specific notesGo To Top

To use c3p0 with JBoss:

  1. Place c3p0's jar file in the lib directory of your jboss server instance (e.g. ${JBOSS_HOME}/server/default/lib)
  2. Modify the file below, and save it as c3p0-service.xml in the deploy directory of your jboss server (e.g. ${JBOSS_HOME}/server/default/deploy). Note that parameters must be capitalized in this file, but otherwise they are defined as described above.

Please note: As of c3p0-0.9.1, the class name of the jboss configuration mbean has changed to com.mchange.v2.c3p0.jboss.C3P0PooledDataSource (from com.mchange.v2.c3p0.mbean.C3P0PooledDataSource), in order to distinguish what is really jboss-specific functionality from c3p0's more general JMX support.

The old jboss config mbeans are deprecated, but will still work. However, support for new configuration parameters will only be added under the new name. Updating requires a one-word change to your c3p0-service.xml, change "mbean" to "jboss" where your old file says 'code="com.mchange.v2.c3p0.mbean.C3P0PooledDataSource"'. Just do it!

Hide box.以下是0.9.2配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>

<server>

   <mbean code="com.mchange.v2.c3p0.mbean.C3P0PooledDataSource"
          name="jboss:service=C3P0PooledDataSource">
     
      <attribute name="JndiName">java:PooledDS</attribute>
      <attribute name="JdbcUrl">jdbc:oracle:thin:@218.85.135.184:1522:BTS</attribute>
      <attribute name="DriverClass">oracle.jdbc.driver.OracleDriver</attribute>
      <attribute name="User">best_bts</attribute>
      <attribute name="Password">best_bts</attribute>

      <!-- Uncomment and set any of the optional parameters below -->
      <!-- See c3p0's docs for more info.                         -->

      <!-- <attribute name="AcquireIncrement">3</attribute>                     -->
      <!-- <attribute name="AcquireRetryAttempts">30</attribute>                -->
      <!-- <attribute name="AcquireRetryDelay">1000</attribute>                 -->
      <!-- <attribute name="AutoCommitOnClose">false</attribute>                -->
      <!-- <attribute name="AutomaticTestTable"></attribute>                    -->
      <!-- <attribute name="BreakAfterAcquireFailure">false</attribute>         -->
      <!-- <attribute name="CheckoutTimeout">0</attribute>                      -->
      <!-- <attribute name="ConnectionTesterClassName">0</attribute>            -->
      <!-- <attribute name="Description">A pooled c3p0 DataSource</attribute>   -->
      <!-- <attribute name="FactoryClassLocation"></attribute>                  -->
      <!-- <attribute name="ForceIgnoreUnresolvedTransactions">true</attribute> -->
      <!-- <attribute name="IdleConnectionTestPeriod">-1</attribute>            -->
      <!-- <attribute name="InitialPoolSize">3</attribute>                      -->
      <!-- <attribute name="MaxIdleTime">0</attribute>                          -->
      <!-- <attribute name="MaxPoolSize">15</attribute>                         -->
      <!-- <attribute name="MaxStatements">0</attribute>                        -->
      <!-- <attribute name="MaxStatementsPerConnection">0</attribute>           -->
      <!-- <attribute name="MinPoolSize">0</attribute>                          -->
      <!-- <attribute name="NumHelperThreads">3</attribute>                     -->
      <!-- <attribute name="PreferredTestQuery"></attribute>                    -->
      <!-- <attribute name="TestConnectionOnCheckin">false</attribute>          -->
      <!-- <attribute name="TestConnectionOnCheckout">false</attribute>         -->
      <!-- <attribute name="UsesTraditionalReflectiveProxies">false</attribute> -->


      <depends>jboss:service=Naming</depends>
   </mbean>

</server>
  评论这张
 
阅读(2158)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018