爱问知识人 爱问教育 医院库

spring是如何对Service进行事务管理的?

首页

spring是如何对Service进行事务管理的?

spring是如何对Service进行事务管理的?

提交回答

全部答案

    2017-07-27 15:17:16
  •   OS:windows 2003 Server
    Web Server: jakarta-tomcat-5。0。28
    DataBase Server: MS SQL Server 2000 (打了SP3补丁)
    IDE: Eclipse 3。
      2。0+MyEclipse 5。0GA 测试案例系统结构: web层Service层DAO层 web层使用struts 1。1,DAO使用的spring的JDBC,spring版本1。2 数据库中有两张表: student1和Student2,表结构相同:id,name,address.其中id为主键且为自增长型。
       student1表中有一条记录: id name address 1 xiaoming wuhan student2表中记录为空 测试情形一: web层捕获异常并处理,DAO层不捕获异常,Service也不捕获异常. Service层接口: public interface StudentManagerService { public void bus_method(); } DAO层接口 public interface StudentDAO { public void deleteStudent1(); public void insertStudent2(); } StudentDAO接口的实现: public class StudentDAOImp extends JdbcDaoSupport implements StudentDAO{ //删除student1表中的id=1的记录 public void deleteStudent1(){ JdbcTemplate jt=this。
      getJdbcTemplate(); jt。update("delete from student1 where id=1"); } //将student1表中删除的记录插入到student2中,但是此方法实现有错,因为 //id字段设置为自增长的,所以在插入记录时我们不能指定值 public void insertStudent2(){ JdbcTemplate jt=this。
      getJdbcTemplate(); String arg[]=new String[3]; arg[0]="1"; arg[1]="xiaoming"; arg[2]="wuhan"; jt。update("insert student2(id,name,address) values(?,?,?)",arg); } } StudentManagerService 接口的实现: public class StudentManagerServiceImp implements StudentManagerService{ private StudentDAO stdDAO; public void setStdDAO(StudentDAO stdDAO){ this。
      stdDAO=stdDAO; } //此方法为事务型的:删除student1中的记录成功且插入student2的记录也成功, //如果insertStudent2()方法执行失败,那么deleteStudent1()方法也应该会失败 public void bus_method(){ this。
      stdDAO。deleteStudent1(); this。stdDAO。insertStudent2(); }。

    即***

    2017-07-27 15:17:16

类似问题

换一换
  • 系统软件 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):