为什么Spring控制不了事务求助各位大神?

public void PlatformAdd(){
       TransactionStatus status=txManager.getTransaction(txDefinition);  
       try {
   transactionDaoImp.add();
   transactionDaoImp.update();
   txManager.commit(status);
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   txManager.rollback(status);
   e.printStackTrace();
  }

 


 public void add()throws SQLException {
  // TODO Auto-generated method stub
  String sql="insert into Springtest values(4,'zhougui')";
   conn= dataSource.getConnection();
   sta=conn.createStatement();
   sta.execute(sql);  
 }

 

public void update() throws SQLException {
  // TODO Auto-generated method stub
  String sql="update springtest set name='guomumin'  where id=";
   conn=dataSource.getConnection();
   sta=conn.createStatement();
   sta.execute(sql); 
 }

 

配置文件:

  <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"/>
  </bean>

 

  <bean id="transactionHandle" class="com.transaction.xml.service.TransactionHandle">
         <property name="transactionDaoImp" ref="transactionDaoImp"></property>
         <property name="transactionTemplate" ref="transactionTemplate"></property>
         <property name="txDefinition" ref="txDefinition"></property>
         <property name="txManager" ref="txManager"></property>
  </bean>

      <bean id="txDefinition" class="org.springframework.transaction.support.DefaultTransactionDefinition">
      <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
      </bean>

 

为什么我控制不了事务 执行sql是sql会报错的

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页