电脑桌面
添加蚂蚁七词文库到电脑桌面
安装后可以在桌面快捷访问

java 开启事务管理,保证数据一致性

来源:金蝶云社区作者:金蝶2024-09-161

java 开启事务管理,保证数据一致性

import javax.sql.DataSource;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.SQLException;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;


@Service

public class ICStockBillServiceImpl extends ServiceImpl<ICStockBillDao, ICStockBillEntity> implements ICStockBillService {


 @Resource

    private DataSource dataSource;


public void TransactionExample () {

Connection connection = null;

        PreparedStatement statement = null;

        try {

            connection = dataSource.getConnection();

            System.out.println("connection"+connection);

            // 设置自动提交为false,禁用事务自动提交

            connection.setAutoCommit(false);

  // 创建Statement

            statement = connection.createStatement();

            

            // 执行一系列操作

            statement.executeUpdate("INSERT INTO YourTable (column1) VALUES ('value1')");

            statement.executeUpdate("UPDATE YourTable SET column1 = 'newValue' WHERE column1 = 'value1'");

            

            // 提交事务

            connection.commit();

            

            System.out.println("事务成功提交!");

        

        } catch (SQLException e) {

            try {

                if (connection != null) {

           

java 开启事务管理,保证数据一致性

import javax.sql.DataSource;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.SQLException;import ...
点击下载文档文档为doc格式

声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

已经是第一篇
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息
QQ群
  • 答案:my7c点击这里加入QQ群
支持邮箱
微信
  • 微信