如何使用sql事务?

发布于 2024-12-15 12:29:30 字数 724 浏览 4 评论 0原文

我有一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微凉 2024-12-22 12:29:30

您需要告诉框架您想要“围绕”您的方法创建事务。就我个人而言,我一直采用使用注释的方式(@Transactional)。网上有很多教程和示例,例如: http://blog.m1key.me/2010/06/spring-3-transaction-management.html

You 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.html

烟─花易冷 2024-12-22 12:29:30

Spring 为您提供了两种选择:

  1. 声明式事务
  2. 编程式事务支持

取决于您要使用剩余代码中的哪一种,最简单的是声明式事务,

将 @Transactional 添加到您的 DAO 类中即可完成。

以下链接应该为您提供一些示例:

  1. http://www.java2s .com/Code/Java/Spring/SetupDataSourceforMySQL.htm

  2. http://www.devdaily.com/java/spring-mysql-java-basicdatasource-connection-example

Spring provides you with two options:

  1. Declarative Transaction
  2. Programmatic Transaction support

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:

  1. http://www.java2s.com/Code/Java/Spring/SetupDataSourceforMySQL.htm

  2. http://www.devdaily.com/java/spring-mysql-java-basicdatasource-connection-example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文