sprin中使用轻量jdbc、c3p0、dbpc的配置

1、JDBC

包:spring-jdbc-4.0.0.RELEASE.jar

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql://localhost:3306/demo?characterEncoding=utf-8"></property>
        <property name="username" value="root"></property>
        <property name="password" value="root"></property>
    </bean>

*:这里建议直接加上字符编码;避免踩坑

2、dbpc

包:commons-dbcp-1.4.jar,commons-pool-1.2.jar

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql:///demo"></property>
        <property name="username" value="root"></property>
        <property name="password" value="root"></property>
    </bean>

 

3、c3p0

包:c3p0-0.9.1.2.jar

<bean name="dataSource" class="com.mchange.v2.c3p0.DriverManagerDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql:///demo"></property>
        <property name="user" value="root" ></property>
        <property name="password" value="root"></property>
    </bean>

 

posted @ 2019-04-01 17:49  杜小二  阅读(151)  评论(0编辑  收藏  举报