Spring3.2.9 + JdbcTemplate 学习
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 学习的更多相关文章
- JdbcTemplate学习笔记
JdbcTemplate学习笔记 1.使用JdbcTemplate的execute()方法执行SQL语句 Java 代码 jdbcTemplate.execute("CREATE TABLE ...
- Spring之JDBCTemplate学习
一.Spring对不同的持久化支持: Spring为各种支持的持久化技术,都提供了简单操作的模板和回调 ORM持久化技术 模板类 JDBC org.springframework.jdbc.core. ...
- 关于freemarker标签+Spring3.0 V层学习
import标签 就是把其他的ftl页面引用进来 <#import "/common/ui.ftl" as ui> 使用时 <@ui.message/>,m ...
- Spring3表达式语言(SpEL)学习笔记
最新地址请访问:http://leeyee.github.io/blog/2011/06/19/spring-expression-language Spring Excpression Langua ...
- JdbcTemplate学习笔记(更新插入删除等)
1.使用JdbcTemplate的execute()方法执行SQL语句 jdbcTemplate.execute("CREATE TABLE USER (user_id integer, n ...
- jdbcTemplate学习(四)
前面三节讲了jdbcTemplate的使用,这一节讲解NamedParameterJdbcTemplate的使用方法: NamedParameterJdbcTemplate类是基于JdbcTempla ...
- jdbcTemplate学习(三)
上一节讲的查询方法,映射结果集为对象时,需要一个个set属性值,比较麻烦,下面讲解使用BeanPropertyRowMapper来将查询结果简单映射成对象: 使用Spring的JdbcTemplate ...
- jdbcTemplate学习(二)
前面讲了增加.删除.更新操作,这节讲一下查询. 查询操作: (一)查询一个值(不需要注入参数) queryForObject(String sql, Class<T> requiredTy ...
- jdbcTemplate学习(一)
概述 Spring JDBC抽象框架core包提供了JDBC模板类,其中JdbcTemplate是core包的核心类,所以其他模板类都是基于它封装完成的,JDBC模板类是第一种工作模式. JdbcTe ...
随机推荐
- PhpStorm2017.1版激活方法、汉化方法以及界面配置
本教程仅对2017.1版有效!!!!!! PhpStorm激活和汉化文件下载网址(提取密码:62cg) PhpStorm的介绍 PhpStorm是一个轻量级且便捷的PHP IDE,其旨在提高用户效率, ...
- 201704 F-02创建财务凭证
一.F-02 创建财务凭证-BDC 期初余额导入程序 程序:ZFIU_LDV_F_02_UPLOAD 创建F-02 凭证: *&-------------------------------- ...
- Python2 socket TCPServer 多线程并发 超时关闭
在阿里云上测试过,可以直接使用. 用IP和端口发送数据,会返回echo:+接收到的数据 #coding=utf-8 import socket import threading,getopt,sys, ...
- Numpy用于数组的文件输入输出
这一章比较简单,内容也比较少.而且对于文件的读写,还是使用pandas比较好.numpy主要是读写文本数据和二进制数据的. 将数组以二进制的格式保存到硬盘上 主要的函数有numpy.save和nump ...
- 阿里云centos+java环境搭建
目录 .准备 .安装jdk .安装tomcat .安装mysql 1.准备 购买阿里云服务器,我买的是Centos 6.5. 因为是linux,在window下管理我使用XManager,这个软件可以 ...
- width
position:absolute 其widht:%是想对于最近的已经定位的父元素,如果没有就想对于body widht 是指的内容区的with,设置除了width其他的元素都会使元素变的比width ...
- UI控件之UIImageView
UIImageView:图像视图,用于在应用程序中显示图片 UIImage:是将图片文件转换为程序中的图片对象 UIImageView是UIImage的载体 方法一:用此方法创建图片对象,会将图片ca ...
- windows下载Mysql-python
Mysql-python第三方模块官方不支持windows系统,而国外大学提供了非官方 的支持windows系统的模块,可前往 https://www.lfd.uci.edu/~gohlke/pyth ...
- CSS3 画点好玩的东西
虽然项目赶工还是挺忙的,但闲了总要找点乐子嘛,毕竟秃顶和猝死两座大山夹逼着编程员们. 好吧,其实是无聊起来我自己都怕,于是就做了点小玩意. .heart { position: relative; t ...
- linux 基础二---用户群租权限
用户&群组&权限 一.用户 1.用户及passwd文件 1) 掌握/etc/passwd文件的功能:存储所有用户的相关信息,该文件也被称为用户信息数据库(Database). 2) / ...