Example With JdbcDaoSupport
By extended the JdbcDaoSupport, set the datasource and JdbcTemplate in your class is no longer required, you just need to inject the correct datasource into JdbcCustomerDAO. And you can get the JdbcTemplate by using a getJdbcTemplate() method.
public class JdbcCustomerDAO extends JdbcDaoSupport implements CustomerDAO
{
//no need to set datasource here
public void insert(Customer customer){ String sql = "INSERT INTO CUSTOMER " +
"(CUST_ID, NAME, AGE) VALUES (?, ?, ?)"; getJdbcTemplate().update(sql, new Object[] { customer.getCustId(),
customer.getName(),customer.getAge()
}); }
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/mkyongjava" />
<property name="username" value="root" />
<property name="password" value="password" />
</bean> </beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="customerDAO" class="com.mkyong.customer.dao.impl.JdbcCustomerDAO">
<property name="dataSource" ref="dataSource" />
</bean> </beans>
Example With JdbcDaoSupport的更多相关文章
- 使用JDBC批量保存数据(JdbcDaoSupport,JdbcTemplete)
最近做的一个项目中用到了Hibernate的,然后数据库批量插入数据的时候就使用到了hibernate的批处理,但是效率比较低,看网上说还有一些限制,要禁止二级缓存,还要多一个batch_size的配 ...
- spring使用JdbcDaoSupport中封装的JdbcTemplate进行query
1.Dept package cn.hxex.springcore.jdbc; public class Dept { private Integer deptNo; private String d ...
- Spring + JdbcTemplate + JdbcDaoSupport examples
In Spring JDBC development, you can use JdbcTemplate and JdbcDaoSupport classes to simplify the over ...
- 给dao层注入jdbcTemplate时的一个强行bug(jdbcDaoSupport不要随便用!用了要记得!)
记录Dao层一个鱼唇至极的错误 这一天我在使用Spring的进行注解配置项目时, 我的Idea给我抛了一个如下的错误: Exception in thread "main" org ...
- Spring(二)继承jdbcDaoSupport的方式实现(增删改查)
一 首先创建数据库表和相应的字段,并创建约束 二 建立项目,导入jar包(ioc,aop,dao,数据库驱动,连接池)并且将applicationContext.xml文件放在src下 三 开启组件扫 ...
- Spring-继承JdbcDaoSupport类后简化配置文件内容
正常情况下,我们在实现类中想要晕用模板类需要在配置文件中注入连接池,再将连接池注入给模板类,然后在实现类中得到. <!-- 配置C3P0连接池 --> <bean id = &quo ...
- spring使用JdbcTemplate和jdbcDaosupport及具名参数使用
关于jdbctemplate: 个人感觉比Java链接mysql那一套方便好维护多了,只需在配置文件维护即可 需要的包: com.springsource.net.sf.cglib-2.2.0.jar ...
- ref:Spring JdbcTemplate+JdbcDaoSupport实例
ref:https://www.yiibai.com/spring/spring-jdbctemplate-jdbcdaosupport-examples.html 在Spring JDBC开发中,可 ...
- [Spring学习笔记 7 ] Spring中的数据库支持 RowMapper,JdbcDaoSupport 和 事务处理Transaction
1.Spring中的数据库支持 把具有相同功能的代码模板抽取到一个工具类中.2.关于jdbc template的应用 jdbcTemplate模板操作类,把访问jdbc的模板抽取到template中, ...
- 搭建事务管理转账案例的环境(强调:简化开发,以后DAO可以继承JdbcDaoSupport类)
1. 步骤一:创建WEB工程,引入需要的jar包 * IOC的6个包 * AOP的4个包 * C3P0的1个包 * MySQL的驱动包 * JDBC目标2个包 * 整合JUnit测试包2.步骤二:创建 ...
随机推荐
- Java并发-CopyOnWriteArrayList
前言 今天我们一起学习下java.util.concurrent并发包里的CopyOnWriteArrayList工具类.当有多个线程可能同时遍历.修改某个公共数组时候,如果不希望因使用synchro ...
- [03] HEVD 内核漏洞之UAF
作者:huity出处:https://www.cnblogs.com/huity35/p/11240997.html版权:本文版权归作者所有.文章在博客园.个人博客同时发布.转载:欢迎转载,但未经作者 ...
- Anacodna之conda的使用
yum install -y bunzip2 wget https://repo.continuum.io/archive/Anaconda2-5.0.1-Linux-x86_64.sh chmod ...
- mysql 不同版本下 group by 组内排序的差异
最近发现网上找的 group by 组内排序语句在不同的mysql版本中结果不一样. 建表语句: SET FOREIGN_KEY_CHECKS=0; -- ---------------- ...
- 基于kubernetes自研容器管理平台的技术实践
一.容器云的背景 伴随着微服务的架构的普及,结合开源的Dubbo和Spring Cloud等微服务框架,宜信内部很多业务线逐渐了从原来的单体架构逐渐转移到微服务架构.应用从有状态到无状态,具体来说将业 ...
- laravel 模型查询总结
1.Model::find($id);//查找主键为$id的数据 2.Model::find([$key1,$key2]);//使用双主键进行查找 3.Model::findOrFail($id);/ ...
- VisualStudio中的单元测试
1. VisualStuio中的测试资源管理器.CodeLens和ReSharper 上一篇文章重温了<单元测试的艺术>里提到的单元测试的技术及原则.这篇文章实践使用VisualStudi ...
- hibernate 命名策略
对于Java开发人员,Hibernate 3 annotations提供了非常好的方式来展示域分层.你可以很轻松的通过Hibernate自动生成需要的数据库架构,带有完整的SQL脚本.然而回到现实世界 ...
- 【iOS】iOS main() 简介
C 语言编写的程序,其执行入口都是 main(). 用 Objective-C 语言编写的程序也是这样. main.m 中的代码如下: int main(int argc, char * argv[] ...
- 【iOS】"OS X"想要进行更改。键入管理员的名称和密码以允许执行此操作("OS X"想使用系统钥匙串)
今天真机调试的时候遇到了这个问题,如下图: 每次调试都要输入两次用户名和密码,好麻烦的说…… 关键时刻找到了这篇文章:"Mac OS X"想要进行更改.键入管理员的名称和密码以允许 ...