applicationContext.xml

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:property-placeholder location="classpath:jdbc.properties"/> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean> <bean id="testService" class="cn.byref.spring.demo.TestServiceImpl">
<property name="testDao" ref="testDao"></property>
</bean> <bean id="testDao" class="cn.byref.spring.demo.TestDaoImpl">
<property name="dataSource" ref="dataSource"></property>
</bean> </beans>

TestDaoImpl.java

package cn.byref.spring.demo;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport; public class TestDaoImpl extends JdbcDaoSupport implements TestDao { @Override
public void addAge(String userName, int age) {
JdbcTemplate tpl = this.getJdbcTemplate();
String sql = "update test set age = ? where username = ?";
int cnt = tpl.update(sql, new Object[] { age, userName});
System.out.println("effected = " + cnt);
} }

TestClass.java

package cn.byref.spring.demo;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.mchange.v2.c3p0.ComboPooledDataSource; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class TestClass { @Resource
private ComboPooledDataSource dataSource; @Resource
private TestDao testDao; @Resource
TestService testService; @Test
public void test(){
// testDao.addAge("侠客", 1001);
testService.addAge("侠客", 110);
}
}

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. Json模块的详细介绍(序列化)

    什么叫序列化——将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化. 比如,我们在python代码中计算的一个数据需要给另外一段程序使用,那我们怎么给? 现在我们能想到的方法就是存在文件里,然 ...

  2. "深入理解C语言" 指针

    本文对coolshell中的"深入理解C语言"这篇文章中提到的指针问题, 进行简要的分析. #include <stdio.h> int main(void){ ]; ...

  3. settings配置 文件操作

    设置文件路径 import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 这里用到了python中一个神奇的变量 __file__ ...

  4. iOS 给 ViewController 减负 之 UITableView

    今天看了一些博客文章分享了如何给ViewController 瘦身的问题, 其中一个就是tableView. 的确,随着产品迭代,VC里面可能越来越臃肿,有时候真的需要好好进行一次瘦身.可能是参考的博 ...

  5. 静态库引入引起的错误解决方案,ld: warning: ignoring file ”…/XXX.a”, file was built for archive which is not the architecture being linked (armv7): “…/XXX.a” Undefined symbols for architecture armv7: "_OBJC_CLASS_$

    想目中不免会引入一些静态库,可是有时加入'.a'文件后编译便会报以下错误 ld: warning: ignoring file ”…/XXX.a”, file was built for archiv ...

  6. springboot-vue项目后台1

  7. linux中安装软件的集中方法

    一.rpm包安装方式步骤: 引用:1.找到相应的软件包,比如soft.version.rpm,下载到本机某个目录:2.打开一个终端,su -成root用户:3.cd soft.version.rpm所 ...

  8. linux系统怎么截图?linux系统中对指定区域进行截图的详细教程

    windows系统的截图相当简单,方法也很多,但是linux下截图已经成为了一个老大难问题,在windows下用惯了qq截图,到了linux下没了qq,那要怎么办呢,prt sc sysrq 键全屏截 ...

  9. python中threading多线程

    python中有两个处理多线程的模块thread和threading.其中thread提供了多线程底层支持的模块,以低级原始的发那个是来处理和控制线程,使用起来较为复杂:而threading基于thr ...

  10. Oracle基本概念

    1. 数据库和实例 什么是数据库,其实很简单,数据库就是存储数据的一种媒介.比如常用的文件就是一种,在Oracle10g中,数据的存储有好几种.第一种是文件形 式,也就是在你的磁盘中创建一批文件,然后 ...