您的位置:首页 > 编程语言 > Java开发

JdbcTemplae使用入门&&Spring三种连接池配置&&Spring配置文件引用外部properties文件

2013-11-01 15:00 736 查看
JdbcTemplate的使用

Spring为了各种支持的持久化技术,都提供了简单操作的模版和回调。

JdbcTemplate 简化 JDBC 操作
HibernateTemplate 简化 Hibernate 操作

下面列出几种熟悉的

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 配置数据库连接池 -->
<!-- 引入外部 properties 文件 -->

<context:property-placeholder location="classpath:jdbc.properties"/>

<!-- 配置c3p0 连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>

<!-- 将连接池注入 jdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>

<!-- 配置DAO -->
<bean id="personDAO" class="cn.itcast.dao.PersonDAO">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>
</beans>


View Code

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐