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.步骤二:创建 ...
随机推荐
- list模板题
题面: 设计一个int类型的动态链表L,L中有一个代表当前位置的光标,支持下列操作: insert(x): 在光标前面插入元素x,插入后光标指向新插入的元素x move(d): 如果d为正数,则光标向 ...
- TensorFlow笔记-图片读取
回到上一篇文件的读取分这么几步: # 构造队列 # 1,构造图片文件的队列 file_queue = tf.train.string_input_producer(filelist) # 构造阅读器 ...
- 给自己的网站加上HTTPS
前言 现在谷歌等厂商大力推行https协议,如果你的网站不支持https,在使用谷歌浏览器时,会被警告网站不安全.w(゚Д゚)w,不安全?哪里不安全了?OK,那我改成支持https好吧.关于http怎 ...
- DEDE(织梦)后台发表文章无法编辑(出现空白)方法
- 基础算法和数据结构高频题 II
DFS的两种理解方式:1. 按照实际执行顺序模拟 (适合枚举型DFS,下节课内容)2. 按照DFS的定义宏观理解 (适合分治型DFS,本节课内容) 1 Convert BST to Greater T ...
- Linux基本操作及安装(部分)
1.分别用cat \tac\nl三个命令查看文件/etc/ssh/sshd_config文件中的内容, 并用自己的话总计出这三个文档操作命令的不同之处? [root@localhost ~]# c ...
- java并发之ConcurrentLinkedQueue
在并发编程中,我们可能经常需要用到线程安全的队列,JDK提供了两种模式的队列:阻塞队列和非阻塞队列.阻塞队列使用锁实现,非阻塞队列使用CAS实现.ConcurrentLinkedQueue是一个基于链 ...
- JavaSE(二)标识符,关键字,数据类型
一.标识符和关键字 1.具有特殊作用的分隔符:分号;.花括号{}.圆括号().空格.圆点 . 2.标识符规则:用于给程序中变量.类.方法命名的符号. Ja ...
- 解决报错:类型“System.Object”在未被引用的程序集中定义。必须添加对程序集“System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”的引用
Razor视图引擎中,使用部分视图编译报错 类型“System.Object”在未被引用的程序集中定义.必须添加对程序集“System.Runtime, Version=4.0.0.0, Cultur ...
- oracle 删除用户,提示“无法删除当前已连接的用户”
1. 首先查询出该用户的登录情况,注意用户名必须是大写 SQL> select username,sid,serial# from v$session where username = 'XST ...