qiqiflying 2008-12-03 15:47
浏览 344
已采纳

我的spring事务为什么不起作用???

接口:
public interface StuDao {

public void insert();
public void delete();
}
public interface StuSer {

public void update();
}
实现:
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import com.test.spring.interf.StuDao;
public class DaoImpl extends JdbcDaoSupport implements StuDao {
public void delete() {
JdbcTemplate jt= this.getJdbcTemplate();
String sql1 = "delete from student1 where id=1";
jt.update(sql1);
}
public void insert() {
JdbcTemplate jt= this.getJdbcTemplate();
String sql = "insert into student2 values (1,'jack','dd')";//这句话会出错
jt.update(sql);
}
}
public class StuSerImpl {
private DaoImpl dao;
public void update() {
try{
this.dao.delete();
this.dao.insert();
}catch(Exception e){
System.out.println("stuSerImpl-----"+e);
}
}
public DaoImpl getDao() {
return dao;
}
public void setDao(DaoImpl dao) {
this.dao = dao;
}
}
action:
public void setStuSerImpl(StuSerImpl stuSerImpl) {
this.stuSerImpl = stuSerImpl;
}
public StuSerImpl getStuSerImpl() {
return this.stuSerImpl;
}
private StuSerImpl stuSerImpl;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
DForm dForm = (DForm) form; // TODO Auto-generated method stub
try{
stuSerImpl.update();
}catch(Exception e){
System.out.println("-------------"+e);
}
return null;
}
}
struts-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://struts.apache.org/dtds/struts-config_1_1.dtd">





attribute="dForm"
name="dForm"
path="/d"
scope="request" type="org.springframework.web.struts.DelegatingActionProxy" />






applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<!--

**

-->


oracle.jdbc.driver.OracleDriver


jdbc:oracle:thin:@****:**


**


**































PROPAGATION_REQUIRED



[b]问题补充:[/b]
上面的写错了,是这样:









PROPAGATION_REQUIRED,-BadSqlGrammarException



[b]问题补充:[/b]
不做异常处理也不行啊。

  • 写回答

4条回答 默认 最新

  • 君临天下11111 2008-12-04 13:58
    关注



    PROPAGATION_REQUIRED


    你这里写错啦,你只做了以de开头的失误处理
    一般我是这样写的
    PROPAGATION_REQUIRED,readOnly
    PROPAGATION_REQUIRED,readOnly
    PROPAGATION_REQUIRED,readOnly
    PROPAGATION_REQUIRED,readOnly
    PROPAGATION_REQUIRED,readOnly
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED,readOnly
    只读失误的设置为PROPAGATION_REQUIRED,readOnly,其他的设置为PROPAGATION_REQUIRED

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能