我是靠谱客的博主 寂寞嚓茶,这篇文章主要介绍事务回滚,现在分享给大家,希望可以做个参考。

public class TransDemo {
    public static void main(String[] args)  {
            Connection connection = null;
            connection = DButil.getConnection();
            System.out.println(null==connection);
        try {
            StudentDaoImpl studentDao = new StudentDaoImpl();
            connection.setAutoCommit(false);
            Student student = new Student(14, "小雪", 18, "女", new Date());
            int i = 1/0;
            studentDao.add(student);//添加
            studentDao.delete(6);
            connection.commit();//提交事务
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("事务回滚了");
            try {
                connection.rollback();//如果抛出异常回滚
            } catch (SQLException ex) {
                throw new RuntimeException(ex);
            }
        }


  }

}

返回事务提交的地方

最后

以上就是寂寞嚓茶最近收集整理的关于事务回滚的全部内容,更多相关事务回滚内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(112)

评论列表共有 0 条评论

立即
投稿
返回
顶部