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>
--------------------------------------------------------------------------------------------------------------------------------------------------------
目前的博客发表主要以记录笔记为主,可能部分内容有些浅显,望各路大牛勿喷,请您雅正