使用开源连接池
jdbc
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql:///spring?useUnicode=true&characterEncoding=utf8" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
dbcp
<!-- dbcp连接池 -->
<bean id="dbcp" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql:///spring?useUnicode=true&characterEncoding=utf8" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
c3p0
<!-- c3p0连接池 -->
<bean id="c3p0" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- <property name="driverClass" value="com.mysql.cj.jdbc.Driver"/> -->
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql:///spring?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC"/>
<property name="user" value="root"/>
<property name="password" value="root"/>
</bean>
druid
<!-- druid连接池 -->
<bean id="druid" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
<property name="url" value="jdbc:mysql:///spring?characterEncoding=utf-8&serverTimezone=GMT%2B8" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
加载驱动 Class.forName("com.mysql.jdbc.Driver");或Class.forName("com.mysql.cj.jdbc.Driver");
在spring中可直接在选定的连接池中配置驱动属性,