applicationContext.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
  6. xmlns:aop="http://www.springframework.org/schema/aop"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context.xsd
  11. http://www.springframework.org/schema/mvc
  12. http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
  13. http://www.springframework.org/schema/aop
  14. http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
  15. http://www.springframework.org/schema/tx
  16. http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
  17.  
  18. <context:property-placeholder location="classpath:jdbc.properties"/>
  19.  
  20. <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  21. <property name="driverClass" value="${jdbc.driverClass}"></property>
  22. <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
  23. <property name="user" value="${jdbc.user}"></property>
  24. <property name="password" value="${jdbc.password}"></property>
  25. </bean>
  26.  
  27. <bean id="testService" class="cn.byref.spring.demo.TestServiceImpl">
  28. <property name="testDao" ref="testDao"></property>
  29. </bean>
  30.  
  31. <bean id="testDao" class="cn.byref.spring.demo.TestDaoImpl">
  32. <property name="dataSource" ref="dataSource"></property>
  33. </bean>
  34.  
  35. </beans>

TestDaoImpl.java

  1. package cn.byref.spring.demo;
  2.  
  3. import org.springframework.jdbc.core.JdbcTemplate;
  4. import org.springframework.jdbc.core.support.JdbcDaoSupport;
  5.  
  6. public class TestDaoImpl extends JdbcDaoSupport implements TestDao {
  7.  
  8. @Override
  9. public void addAge(String userName, int age) {
  10. JdbcTemplate tpl = this.getJdbcTemplate();
  11. String sql = "update test set age = ? where username = ?";
  12. int cnt = tpl.update(sql, new Object[] { age, userName});
  13. System.out.println("effected = " + cnt);
  14. }
  15.  
  16. }

TestClass.java

  1. package cn.byref.spring.demo;
  2.  
  3. import javax.annotation.Resource;
  4.  
  5. import org.junit.Test;
  6. import org.junit.runner.RunWith;
  7. import org.springframework.test.context.ContextConfiguration;
  8. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  9.  
  10. import com.mchange.v2.c3p0.ComboPooledDataSource;
  11.  
  12. @RunWith(SpringJUnit4ClassRunner.class)
  13. @ContextConfiguration("classpath:applicationContext.xml")
  14. public class TestClass {
  15.  
  16. @Resource
  17. private ComboPooledDataSource dataSource;
  18.  
  19. @Resource
  20. private TestDao testDao;
  21.  
  22. @Resource
  23. TestService testService;
  24.  
  25. @Test
  26. public void test(){
  27. // testDao.addAge("侠客", 1001);
  28. testService.addAge("侠客", 110);
  29. }
  30. }

Spring3.2.9 + JdbcTemplate 学习的更多相关文章

  1. JdbcTemplate学习笔记

    JdbcTemplate学习笔记 1.使用JdbcTemplate的execute()方法执行SQL语句 Java 代码 jdbcTemplate.execute("CREATE TABLE ...

  2. Spring之JDBCTemplate学习

    一.Spring对不同的持久化支持: Spring为各种支持的持久化技术,都提供了简单操作的模板和回调 ORM持久化技术 模板类 JDBC org.springframework.jdbc.core. ...

  3. 关于freemarker标签+Spring3.0 V层学习

    import标签 就是把其他的ftl页面引用进来 <#import "/common/ui.ftl" as ui> 使用时 <@ui.message/>,m ...

  4. Spring3表达式语言(SpEL)学习笔记

    最新地址请访问:http://leeyee.github.io/blog/2011/06/19/spring-expression-language Spring Excpression Langua ...

  5. JdbcTemplate学习笔记(更新插入删除等)

    1.使用JdbcTemplate的execute()方法执行SQL语句 jdbcTemplate.execute("CREATE TABLE USER (user_id integer, n ...

  6. jdbcTemplate学习(四)

    前面三节讲了jdbcTemplate的使用,这一节讲解NamedParameterJdbcTemplate的使用方法: NamedParameterJdbcTemplate类是基于JdbcTempla ...

  7. jdbcTemplate学习(三)

    上一节讲的查询方法,映射结果集为对象时,需要一个个set属性值,比较麻烦,下面讲解使用BeanPropertyRowMapper来将查询结果简单映射成对象: 使用Spring的JdbcTemplate ...

  8. jdbcTemplate学习(二)

    前面讲了增加.删除.更新操作,这节讲一下查询. 查询操作: (一)查询一个值(不需要注入参数) queryForObject(String sql, Class<T> requiredTy ...

  9. jdbcTemplate学习(一)

    概述 Spring JDBC抽象框架core包提供了JDBC模板类,其中JdbcTemplate是core包的核心类,所以其他模板类都是基于它封装完成的,JDBC模板类是第一种工作模式. JdbcTe ...

随机推荐

  1. PhpStorm2017.1版激活方法、汉化方法以及界面配置

    本教程仅对2017.1版有效!!!!!! PhpStorm激活和汉化文件下载网址(提取密码:62cg) PhpStorm的介绍 PhpStorm是一个轻量级且便捷的PHP IDE,其旨在提高用户效率, ...

  2. 201704 F-02创建财务凭证

    一.F-02 创建财务凭证-BDC 期初余额导入程序 程序:ZFIU_LDV_F_02_UPLOAD 创建F-02 凭证: *&-------------------------------- ...

  3. Python2 socket TCPServer 多线程并发 超时关闭

    在阿里云上测试过,可以直接使用. 用IP和端口发送数据,会返回echo:+接收到的数据 #coding=utf-8 import socket import threading,getopt,sys, ...

  4. Numpy用于数组的文件输入输出

    这一章比较简单,内容也比较少.而且对于文件的读写,还是使用pandas比较好.numpy主要是读写文本数据和二进制数据的. 将数组以二进制的格式保存到硬盘上 主要的函数有numpy.save和nump ...

  5. 阿里云centos+java环境搭建

    目录 .准备 .安装jdk .安装tomcat .安装mysql 1.准备 购买阿里云服务器,我买的是Centos 6.5. 因为是linux,在window下管理我使用XManager,这个软件可以 ...

  6. width

    position:absolute 其widht:%是想对于最近的已经定位的父元素,如果没有就想对于body widht 是指的内容区的with,设置除了width其他的元素都会使元素变的比width ...

  7. UI控件之UIImageView

    UIImageView:图像视图,用于在应用程序中显示图片 UIImage:是将图片文件转换为程序中的图片对象 UIImageView是UIImage的载体 方法一:用此方法创建图片对象,会将图片ca ...

  8. windows下载Mysql-python

    Mysql-python第三方模块官方不支持windows系统,而国外大学提供了非官方 的支持windows系统的模块,可前往 https://www.lfd.uci.edu/~gohlke/pyth ...

  9. CSS3 画点好玩的东西

    虽然项目赶工还是挺忙的,但闲了总要找点乐子嘛,毕竟秃顶和猝死两座大山夹逼着编程员们. 好吧,其实是无聊起来我自己都怕,于是就做了点小玩意. .heart { position: relative; t ...

  10. linux 基础二---用户群租权限

    用户&群组&权限 一.用户 1.用户及passwd文件 1) 掌握/etc/passwd文件的功能:存储所有用户的相关信息,该文件也被称为用户信息数据库(Database). 2) / ...