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

dbcp、c3p0、jdbc常用连接配置

dbcp连接数据库配置  比较常见

	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
	    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
	    <property name="url" value="jdbc:mysql://localhost:3306/test"/>
	    <property name="username" value="root"/>
	    <property name="password" value="root"/>
	    <property name="initialSize" value="5"/>
	    <property name="maxActive" value="8"/>
	    <property name="maxIdle" value="40"/>
	    <property name="minIdle" value="2"/>
	</bean> 

c3po连接数据库  GAE/BAE等云空间不允许使用。

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">  
        <property name="driverClass" value="com.mysql.jdbc.Driver" />  
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test"/>  
        <property name="user" value="root"/>  
        <property name="password" value="root"/>  
        <property name="maxPoolSize" value="40"/>  
        <property name="minPoolSize" value="1"/>  
        <property name="initialPoolSize" value="1"/>  
        <property name="maxIdleTime" value="20"/>  
    </bean> 

springframework.jdbc 万能连接

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
    	<property name="driverClassName" value="${jdbc.driverClassName}" />  
    	<property name="url" value="${jdbc.url}" />  
    </bean>
jdbc.properties
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost\:3306/test?user\=root&password\=root&useUnicode\=true&characterEncoding\=UTF-8

打包下载

http://download.csdn.net/detail/xiaocie3456/6484371