Spring从菜鸟到高手(四)(上)使用JdbcTemplate类实现用户登陆验证、批量更新
2006-09-24 16:18
921 查看
看了我前面几篇文章的朋友我相信基础已经有了,不知道大家在使用JDBC连接数据库的时候是不是厌倦了,不停的捕获异常不停的try catch 反正我是厌倦了,代码没写多少,一大半是异常的抓取,Spring的高手们也知道我们厌倦了,所以他们给我们一个JdbcTemplate类这个类把所有的异常抓取代码封装在类的内部,我们要做的只是处理业务逻辑就行了,好了,我来给大家介绍一下吧
org.springframework.jdbc.core
All Implemented Interfaces: InitializingBean, JdbcOperations
JdbcTemplate类的一个方法
用于对PreparedStatement对象的处理可是该如何处理呢?看看PreparedStatementCreator类吧
org.springframework.jdbc.core
这个接口只有一个方法
这个方法对一个Connection连接进行处理返回一个 PreparedStatement对象给JdbcTemplate
那么execute方法的另一个参数PreparedStatementCallback又是干什么的呢?
org.springframework.jdbc.core
All Known Implementing Classes: AbstractLobCreatingPreparedStatementCallback
这个接口也只有一个方法
这个方法对PreparedStatement对象进行处理返回一个结果,这下大家可能有一点了解了,不了解也没事,因为一开始我就不太明白,看看我的代码吧
现在还要向大家介绍JdbcTemplate类的另一个方法
批量更新这个方法接受一个BatchPreparedStatementSetter类对象
org.springframework.jdbc.core
这个接口有两个方法一个是返回一个整数告诉JdbcTemplate需要更新几条信息,另一个方法是对PreparedStatemten对象设置值,看代码...
对字符串进行拆分赋值
Junit测试运行类
核心类
运行结果
我的MyPreparedStatementCreator类
我的MYPreparedStatementCallback类
添加的XML1
添加的XML2
XML配置文件
org.springframework.jdbc.core
Class JdbcTemplate
java.lang.Object org.springframework.jdbc.support.JdbcAccessor org.springframework.jdbc.core.JdbcTemplate
All Implemented Interfaces: InitializingBean, JdbcOperations
JdbcTemplate类的一个方法
Object | execute(PreparedStatementCreator psc, PreparedStatementCallback action) Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. |
org.springframework.jdbc.core
Interface PreparedStatementCreator
这个接口只有一个方法PreparedStatement | createPreparedStatement(Connection con) Create a statement in this connection. |
那么execute方法的另一个参数PreparedStatementCallback又是干什么的呢?
org.springframework.jdbc.core
Interface PreparedStatementCallback
All Known Implementing Classes: AbstractLobCreatingPreparedStatementCallback这个接口也只有一个方法
Object | doInPreparedStatement(PreparedStatement ps) Gets called by JdbcTemplate.executewith an active JDBC PreparedStatement. |
现在还要向大家介绍JdbcTemplate类的另一个方法
int[] | batchUpdate(String sql, BatchPreparedStatementSetter pss) Issue multiple updates on a single PreparedStatement, using JDBC 2.0 batch updates and a BatchPreparedStatementSetter to set values. |
org.springframework.jdbc.core
Interface BatchPreparedStatementSetter
int | getBatchSize() Return the size of the batch. |
void | setValues(PreparedStatement ps,int i) Set values on the given PreparedStatement. |
对字符串进行拆分赋值
Junit测试运行类
核心类
运行结果
我的MyPreparedStatementCreator类
我的MYPreparedStatementCallback类
添加的XML1
添加的XML2
XML配置文件
相关文章推荐
- Spring从菜鸟到高手(四)(上)使用JdbcTemplate类实现用户登陆验证、批量更新
- Spring从菜鸟到高手(四)(上)使用JdbcTemplate类实现用户登陆验证、批量更新
- Spring从菜鸟到高手(四)(上)使用JdbcTemplate类实现用户登陆验证、批量更新
- Spring从菜鸟到高手(四)(下)使用JdbcTemplate类实现批量查询
- Spring从菜鸟到高手(四)(下)使用JdbcTemplate类实现批量查询
- Spring从菜鸟到高手(四)(下)使用JdbcTemplate类实现批量查询
- Spring 使用JdbcTemplate类实现批量查询(RowMapper)
- Django---用户注册和登陆验证(3)--具体实现--使用默认的
- 使用mssql2008新特性(存储过程参数类型使用"用户自定义表"来实现批量DML更新多表)解决项目里遇到的性能问题
- java操作xml之dom4j中的xpath实现用户登陆验证
- 使用asp.net实现防止用户多点登陆
- PHP中使用crypt()实现用户身份验证的代码
- SpringBoot学习笔记之CXF集成(实现用户验证)
- 从零开始学 Java - Spring AOP 实现用户权限验证
- 使用HttpContext中的User属性来实现用户身份验证之用户验证票篇
- 使用manven+hibernate+spring+shiro登录验证实现简单增删改查
- 5.JSP之使用jsp:forward实现用户信息验证的页面跳转
- 在Linux中使用MD5实现用户验证的解决方法
- ASP.NET jQuery 实例12 通过使用jQuery validation插件简单实现用户注册页面验证功能
- 【MVC】使用Servlet 作为控制器实现一个简单的登陆验证