首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

Spring 之dataSource配备(jcbc,c3p0,dbcp,dndi)

2012-08-28 
Spring 之dataSource配置(jcbc,c3p0,dbcp,dndi)1. jdbc配置bean iddataSource value /property n

Spring 之dataSource配置(jcbc,c3p0,dbcp,dndi)
1. jdbc配置

<bean id="dataSource" value="" /><property name="username" value="" /></bean>


2.使用已有连接池。
dbcp:
        <bean id="dataSource" destroy-method="close">        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>        <property name="url" value=""/>        <property name="username" value="xx"/>        <property name="password" value="xx"/>        <property name="maxActive" value="120"/>        <property name="initialSize" value="50"/>        <property name="maxIdle" value="100"/>        <property name="minIdle" value="100"/>        <property name="maxWait" value="150"/>        <property name="defaultAutoCommit" value="true"/>        <property name="removeAbandoned" value="true"/>        <property name="removeAbandonedTimeout" value="600"/>        <property name="logAbandoned" value="true"/>        <property name="validationQuery" value="SELECT 1"/>        <property name="testOnBorrow" value="true" />        <property name="testOnReturn" value="false" />        <property name="testWhileIdle" value="true"/>        <property name="timeBetweenEvictionRunsMillis" value="600000"/>        <property name="minEvictableIdleTimeMillis" value="900000"/>    </bean>


c3p0:
        <bean id="dataSource" destroy-method="close">        <property name="driverClass" value="com.mysql.jdbc.Driver"/>        <property name="jdbcUrl" value=""/>        <property name="user" value="xx"/>        <property name="password" value="xx"/>        <property name="initialPoolSize" value="60" />        <property name="minPoolSize" value="50" />        <property name="maxPoolSize" value="100" />        <property name="maxIdleTime" value="7200" />        <property name="idleConnectionTestPeriod" value="360" />        <property name="preferredTestQuery" value="select 1" />        <property name="acquireIncrement" value="5" />        <property name="acquireRetryAttempts" value="50" />        <property name="acquireRetryDelay" value="1000" />        <property name="breakAfterAcquireFailure" value="true" />        <property name="checkoutTimeout" value="1000" />        <property name="autoCommitOnClose" value="false" />        <property name="forceIgnoreUnresolvedTransactions" value="false" />        <property name="unreturnedConnectionTimeout" value="1000" />        <property name="maxStatements" value="0" />        <property name="maxStatementsPerConnection" value="0" />        <property name="testConnectionOnCheckin" value="true" />        <property name="testConnectionOnCheckout" value="false" />        <property name="usesTraditionalReflectiveProxies" value="false" />        <property name="numHelperThreads" value="5" />    </bean>


3.Jndi

tomcat--context.jndi
<Resource name="jdbc/crm" author="Container" type="javax.sql.DataResource" drivermanager="oracle.jdbc.driver.OracleDriver"  url="" username=""  password=""  maxActive=""  maxidle=""  maxWait="" /> 


web.xml:
  <resource-ref>  <res-ref-name>jdbc/crm</res-ref-name>  <res-type>javax.sql.DataSource</res-type>  <res-auth>Container</res-auth>  </resource-ref>


applicationContext.xml:
<bean id="dataSource" value="java:comp/env/jdbc/crm" /><!-- 如果不想使用java:comp/env前缀的话设置为true <property name="recourceRef" value="true" />--></bean>


热点排行