JDBC、C3P0、DBCP三种链接数据库配置
程序员文章站
2022-05-24 12:00:06
...
第一种
<!--内置的链接池 先配置链接池 -->
<!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" ></property>
<property name="url" value="jdbc:mysql://rm-uf63dht8ci6vxa03lo.mysql.rds.aliyuncs.com:3306/spring_day03"></property>
<property name="username" value="root"></property>
<property name="password" value="WWWqq2_09_01334"></property>
</bean>
-->
<!-- 配置jdbc模板类 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
第二种
<!--配置C3P0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://rm-uf63dht8ci6vxa03lo.mysql.rds.aliyuncs.com:3306/spring_day03" />
<property name="user" value="root" />
<property name="password" value="WWWqq2_09_01334" />
</bean>
第三种
<!--配置DBCP的连接池 -->
<!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://rm-uf63dht8ci6vxa03lo.mysql.rds.aliyuncs.com:3306/spring_day03" />
<property name="username" value="root" />
<property name="password" value="WWWqq2_09_01334" />
</bean> -->
下一篇: Python eval 函数妙用