当前位置:网站首页>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
边栏推荐
- SQL注入
- container
- Use Matplotlib. In Jupiter notebook Pyplot server hangs up and crashes
- ValueError: loaded state dict contains a parameter group that doesn‘t match the size of optimizer‘s
- A general U-shaped transformer for image restoration
- Write your own redistemplate
- PyTorch入门小笔记——利用简单例子观察前向传播各个层输出的size
- Pyqy5 learning (4): qabstractbutton + qradiobutton + qcheckbox
- Filebrowser realizes private network disk
- 数字图像处理基础(冈萨雷斯)一
猜你喜欢

Complete example demonstration of creating table to page - joint table query

你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问

PyQy5学习(四):QAbstractButton+QRadioButton+QCheckBox

Anaconda installed pyqt5 and pyqt5 tools without designer Exe problem solving

String notes

JDBC连接数据库

图解numpy数组矩阵

Latex快速入门

关于二叉树的遍历

Pytorch学习记录(十三):循环神经网络((Recurrent Neural Network)
随机推荐
你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问
给yarn配置国内镜像加速器
The attendance client date of K / 3 wise system can only be selected to 2019
建表到页面完整实例演示—联表查询
CONDA virtual environment management (create, delete, clone, rename, export and import)
图解HashCode存在的意义
Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi
PyQy5学习(三):QLineEdit+QTextEdit
PyTorch笔记——实现线性回归完整代码&手动或自动计算梯度代码对比
去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention
String notes
Solution record of slow access speed of SMB service in redhat6
Opensips (1) -- detailed process of installing opensips
数字图像处理基础(冈萨雷斯)二:灰度变换与空间滤波
Pyqy5 learning (2): qmainwindow + QWidget + qlabel
Unsupervised denoising - [tmi2022] ISCL: dependent self cooperative learning for unpaired image denoising
Pytoch learning record (x): data preprocessing + batch normalization (BN)
Pytorch Learning record (XIII): Recurrent Neural Network
异常的处理:抓抛模型
解决报错:ImportError: IProgress not found. Please update jupyter and ipywidgets