如何使用sql事务?
我有一个带有 ndbcluster 引擎的 Mysql 服务器,它支持事务。
我想在带有 Spring JDBC 框架 3.0.6 的 tomcat 6 下对我的 Java 应用程序使用事务。
我在 web.xml 中配置了一个名为 idDataSource 的数据源 bean。
我添加了以下内容:
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="idDataSource"/>
</bean>
创建 txManager bean。
我在以下网址阅读了文档: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html
不幸的是我真的迷路了。我知道我可能需要实现某种交易接口,但我不知道是哪个。任何信息将不胜感激!
谢谢
I have a Mysql server with ndbcluster engine which supports transactions.
I want to use transactions with my Java application under tomcat 6 with Spring JDBC framework 3.0.6.
I have a DataSource bean called idDataSource configured in my web.xml.
i added the following:
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="idDataSource"/>
</bean>
to create the txManager bean.
I read the docs at the following url: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html
unfortunately I'm really really lost. I understood that I may need to implement some kind of transaction interface but I have no idea which. any information would be greatly appreciated!!!
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要告诉框架您想要“围绕”您的方法创建事务。就我个人而言,我一直采用使用注释的方式(@Transactional,
)。网上有很多教程和示例,例如: http://blog.m1key.me/2010/06/spring-3-transaction-management.htmlYou need to tell the framework that you want to create a transaction 'around' your method(s). Personally, I've always gone the way of using annotations (@Transactional,
<tx:annotation-driven/>
). There are lots of tutorials and examples floating around the 'net, for example: http://blog.m1key.me/2010/06/spring-3-transaction-management.htmlSpring 为您提供了两种选择:
取决于您要使用剩余代码中的哪一种,最简单的是声明式事务,
将 @Transactional 添加到您的 DAO 类中即可完成。
以下链接应该为您提供一些示例:
http://www.java2s .com/Code/Java/Spring/SetupDataSourceforMySQL.htm
http://www.devdaily.com/java/spring-mysql-java-basicdatasource-connection-example
Spring provides you with two options:
Depending on which one you want to use your remaining code depends, easiest is Declarative Transaction,
Add @Transactional to your DAO class and you are done.
Following Links should provide you with some examples:
http://www.java2s.com/Code/Java/Spring/SetupDataSourceforMySQL.htm
http://www.devdaily.com/java/spring-mysql-java-basicdatasource-connection-example