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 ...
随机推荐
- python中json.dumps使用的坑以及字符编码
我们知道,python中的字符串分普通字符串和unicode字符串,一般从数据库中读取的字符串会自动被转换为unicode字符串 下面回到重点,使用json.dumps时,一般的用法为: >&g ...
- Javascript自动打开匹配的超链接
可以用来点击广告.... 部分代码: function AutoClick() { var DivLink=document.getElementById("divLink"); ...
- 爬虫基础库之Selenium
1.简介 selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决requests无法直接执行JavaScript代码的问题 selenium本质是通过驱动浏览器,完全模拟浏览器的操作, ...
- Python 9 sqlalchemy ORM
一.ORM介绍: orm英文全称object relational mapping,就是对象映射关系程序,简单来说我们类似python这种面向对象的程序来说一切皆对象,但是我们使用的数据库却都是关系型 ...
- 【leetcode刷题笔记】Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters ...
- LVS/NAT 配置
LVS/NAT 配置 实验环境 三台主机:Linux Centos 6.4 32位 调度器Director:192.168.1.160(内网IP).192.168.2.20(公网IP) HTTP真实服 ...
- iOS应用网络安全之HTTPS
移动互联网开发中iOS应用的网络安全问题往往被大部分开发者忽略,iOS9和OS X 10.11开始Apple也默认提高了安全配置和要求.本文以iOS平台App开发中对后台数据接口的安全通信进行解析和加 ...
- GCC编译器入门[转载]
GCC编译器(GNU C Compiler)是GNU组织的一款开源 编译器,它是Linux环境下的默认C语言编译器.它处理能够高效的编译C语言以外,还可以编译其他语言.并且,现在的GCC已经不光包括编 ...
- vmxnet3 丢包处理
https://vswitchzero.com/2017/09/26/vmxnet3-rx-ring-buffer-exhaustion-and-packet-loss/
- uniqueidentifier in SQL becomes lower case in c#
https://stackoverflow.com/questions/16938151/uniqueidentifier-in-sql-becomes-lower-case-in-c-sharp ...