一个事务就行了。 实现数据的完整性。
public a(){
yourconnect.setAutoCommit(false);
a1();
a2();
a3();
yourconnect.setAutoCommit(true);
yourconnect.commit();
}
public a(){
yourconnect.setAutoCommit(false);
a1();
a2();
a3();
yourconnect.setAutoCommit(true);
yourconnect.commit();
}
解决方案 »
- Android中怎么为ItemizedOverlay添加点击事件响应,会的不会的都进来看一下吧,我出100分。有点闹心
- 请大家帮帮忙!!
- struts 基础问题 望高手解答 面试工作要用的 急急急急急急急急急急急急急急
- 两句完全正确的HQL语句,为什么一个行一个不行?
- 我下载的jboss-4.0.5.GA,怎么运行一直有问题?
- Spring出来Ioc其他还有什么用吗?依赖注入到底优势在哪里
- 如何删掉<?xml version="1.0" encoding="UTF-8"?>?
- JB+WebLogic 的简单问题在线给分
- 用jbuilder创建不了struts怎么办?
- ^_^一个关于DataSource数据源的问题
- 下面这个错误怎么解决啊!急
- 请介绍一下,在struts下如何使用tiles。。。
可是我还是有一个疑问,就是:
我在a1(),a2(),a3()里都向数据库对象进行了commit()的操作,
(我想这一步的作用是把操作过的数据向数据库里进行实际的提交吧!)
那么,只是如果其中某一个出错了,向数据库中提交的那些数据也会恢复回来吗?ThanX!对了,还有一个想问一楼的老大,所谓的事务嵌套,
是不是说如果我在a1,a2,a3里面已经有了事务处理的代码(处理他们各自的事务),
在他们被调用的时候,也可以再次使用事务处理,来处理a1,a2,a3之间的关系呢?谢谢谢谢谢谢谢谢
<method>
<ejb-name>SystemSetupSession</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>上面*代表SystemSetupSession下所有方法都要进行事务处理;
Required是默认项,代表当一个客户程序请求它时,如果客户程序不在事务中,那么产生一个新的事务,如果在,就包含到了客户程序中的事务中去了。
确实如你所说 可以那么做关于用容器控制事务 我也觉得很不错
一般对于一个Bean中的所有方法都设成Required 出错时自动Rollback
如果设成Support 那么方法A本身不会Rollback 但是方法A中调用的方法B如果是Required那么这个方法B会Rollback
如果设成Not Support 方法B就算是Required在方法A中被调用的话也不能RollBack了
还有Requred new创建一个新的事务
暂时就记得这么多
比如A调用B,那么这个A的事务处理应该怎么设置?
还有B的事务处理又怎么设置呢?
(B的事务处理是不是就是要和tianboguang(其实,我是一个程序员)说的那样呢?)to tianboguang(其实,我是一个程序员):
我用你的方法,把B的ejb-jar.xml像你说的那样改了,
但是在用ant编译的时候,出现了
ejbc: [java] Warning: In 'ejb-jar.xml', EJB 'AppendFunctionsEjbHome' has containe
r-transactions set when the EJB has a transaction-type of 'Bean'. The container-
transaction settings will be ignored.
的错误。
在启动weblogic的时候,也出现了
Warning: In 'ejb-jar.xml', EJB 'AppendFunctionsEjbHome' has container-transactio
ns set when the EJB has a transaction-type of 'Bean'. The container-transaction
settings will be ignored.
的错误提示! 是不是我的那个调用他的ejbbean的ejb-jar.xml有什么问题呢?
需要怎么改呢?AppendFunctions是我那个被调用的ejbbean,其中有事务处理的内容!
是说你设置的容器事务将被不理睬,因为你的客户程序已经在一个事务中了,你设置的“Required”代表当一个客户程序请求它时,如果客户程序不在事务中,那么产生一个新的事务,如果在,就包含到了客户程序中的事务中去了。
以下是J2EE指南里的描述:
Required
If the client is running within a transaction and invokes the enterprise bean's method, the method executes within the client's transaction. If the client is not associated with a transaction, the container starts a new transaction before running the method. The Required attribute will work for most transactions. Therefore, you may want to use it as a default, at least in the early phases of development. Because transaction attributes are declarative, you can easily change them at a later time.