当前位置:网站首页>JDBC operation transaction
JDBC operation transaction
2022-04-23 06:00:00 【hanyc..】
package com.hyc.study04;
import com.hyc.study02.utils.JDBCUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class TestTransaction {
public static void main(String[] args) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
connection = JDBCUtils.getConnection();
// Turn off automatic transaction commit , Turn on transactions automatically
connection.setAutoCommit(false);
String sqlOut = "UPDATE `account` SET `money`=money-100 WHERE `id`=?";
preparedStatement = connection.prepareStatement(sqlOut);
preparedStatement.setInt(1,1);
preparedStatement.executeUpdate();
String sqlIn = "UPDATE `account` SET `money`=money+100 WHERE `id`=?";
preparedStatement = connection.prepareStatement(sqlIn);
preparedStatement.setInt(1,2);
preparedStatement.executeUpdate();
// Business operation completed , Commit transaction
connection.commit();
} catch (SQLException throwables) {
try {
connection.rollback();
} catch (SQLException e) {
e.printStackTrace();
}
throwables.printStackTrace();
}finally {
JDBCUtils.release(connection,preparedStatement,resultSet);
}
}
}
版权声明
本文为[hanyc..]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230541159514.html
边栏推荐
- What is the difference between the basic feasible solution and the basic feasible solution in linear programming?
- Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images
- Pyqy5 learning (4): qabstractbutton + qradiobutton + qcheckbox
- Implementation of displaying database pictures to browser tables based on thymeleaf
- Chapter 4 of line generation - linear correlation of vector systems
- Shansi Valley P290 polymorphism exercise
- Remedy after postfix becomes a spam transit station
- Manually delete registered services on Eureka
- Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots
- Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)
猜你喜欢

Pytorch学习记录(十一):数据增强、torchvision.transforms各函数讲解

Chapter 4 of line generation - linear correlation of vector systems
![去噪论文——[Noise2Void,CVPR19]Noise2Void-Learning Denoising from Single Noisy Images](/img/9d/487c77b5d25d3e37fb629164c804e2.png)
去噪论文——[Noise2Void,CVPR19]Noise2Void-Learning Denoising from Single Noisy Images

filebrowser实现私有网盘

Anaconda
![How to use comparative learning to do unsupervised - [cvpr22] training & [eccv20] image translation](/img/33/780b80693f70112eebc10941f7c134.png)
How to use comparative learning to do unsupervised - [cvpr22] training & [eccv20] image translation

Get the value of state in effects in DVA

关于二叉树的遍历

Automatic control (Han min version)

JVM family (4) -- memory overflow (OOM)
随机推荐
Anaconda installed pyqt5 and pyqt5 tools without designer Exe problem solving
PyTorch笔记——观察DataLoader&用torch构建LeNet处理CIFAR-10完整代码
Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
ValueError: loaded state dict contains a parameter group that doesn‘t match the size of optimizer‘s
深度学习基础——简单了解meta learning(来自李宏毅课程笔记)
Implementation of displaying database pictures to browser tables based on thymeleaf
Pytorch——数据加载和处理
Pytorch learning record (IX): convolutional neural network in pytorch
Configure domestic image accelerator for yarn
Contrôle automatique (version Han min)
Chapter 4 of line generation - linear correlation of vector systems
图解HashCode存在的意义
The official website of UMI yarn create @ umijs / UMI app reports an error: the syntax of file name, directory name or volume label is incorrect
SQL注入
字符串(String)笔记
给yarn配置国内镜像加速器
PyEMD安装及简单使用
Linear algebra Chapter 2 - matrices and their operations
Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
JSP syntax and JSTL tag