Spring 连接 Jdbc
2015-12-14 20:03
363 查看
通过xml配置,用spring连接jdbc
DAO 父类
<?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" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <!-- bellow read only begin --> <tx:annotation-driven transaction-manager="txManager" /> <context:property-placeholder location="classpath:/subs.properties" ignore-unresolvable="true"/> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="jdbcTemplate" lazy-init="true" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="namedJdbcTemplate" lazy-init="true" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate"> <constructor-arg index="0" ref="dataSource" /> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${ddns_driverClassName}" /> <property name="url" value="${ddns_dbUrl}" /> <property name="username" value="${ddns_dbUsername}" /> <property name="password" value="${ddns_password}" /> </bean> </beans>
DAO 父类
public abstract class DDSDAO { /** * used for injecting NamedParameterJdbcTemplate. */ @Autowired protected transient NamedParameterJdbcTemplate namedJdbcTemplate; /** * used for injecting tableSchema. */ @Value("${ddsSchema}") protected String tableSchema; protected JdbcTemplate getJdbcTemplate() { return (JdbcTemplate) namedJdbcTemplate.getJdbcOperations(); } }
相关文章推荐
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- 模拟Spring的简单实现
- spring+html5实现安全传输随机数字密码键盘
- Spring中属性注入详解
- SpringMVC框架下JQuery传递并解析Json格式的数据是如何实现的
- struts2 spring整合fieldError问题
- spring的jdbctemplate的crud的基类dao
- 读取spring配置文件的方法(spring读取资源文件)
- Spring Bean基本管理实例详解
- java实现简单美女拼图游戏
- 详解Java的Spring框架中的事务管理方式
- 解析Java的Spring框架的BeanPostProcessor发布处理器
- Java开发框架spring实现自定义缓存标签
- java基本教程之线程休眠 java多线程教程
- JSP开发中在spring mvc项目中实现登录账号单浏览器登录
- spring boot实战之内嵌容器tomcat配置
- 浅析Java的Spring框架中IOC容器容器的应用
- 基于Spring框架的Shiro配置方法