当前位置:网站首页>How to add transactions in JDBC
How to add transactions in JDBC
2022-07-01 19:41:00 【Desire and Yu Yu】
Problem description
JDBC How to add transactions in
Solution :
public static void main(String[] args) throws Exception {
//1.0 Registration drive
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://01.01.01.01:3306/demo01";
String userName="demo01";
String passWord="123456";
Connection conn= DriverManager.getConnection(url,userName,passWord);
// Definition sql
String sql ="update tb_account set money=money+500 where `Name`=' Zhang San '";
Statement stmt=conn.createStatement();
try{
// Open transaction false: Manual submission true: Automatic submission
conn.setAutoCommit(false);
// perform sql Get the number of affected rows
int count =stmt.executeUpdate(sql);
// Print the results
System.out.println(count);
} catch(Exception throwables){
// Roll back the transaction
conn.rollback();
throwables.printStackTrace();
}
// Release resources
stmt.close();;
conn.close();
边栏推荐
- GB28181的NAT穿透
- Ffmpeg error code
- A brief understanding of white box encryption technology
- 面试题 16.16. 部分排序-双指针法
- 【无标题】
- [Mori city] random talk on GIS data (I)
- Mysql查询结果去除换行
- Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
- 采集抖音视频
- After studying 11 kinds of real-time chat software, I found that they all have these functions
猜你喜欢

JS的Proxy

Wireshark packet analysis TCP, FTP

测试自学人必看:软件测试如何找测试项目?

Oracle物理体系结构

Solution and summary of Nacos startup failure

HLS4ML进入方法

Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference

The use of subplot function in MATLAB

optaplanner学习笔记(一)案例Cloud balance

uni-app商品分类
随机推荐
自定义插入页面标签以及实现类似通讯录的首字母搜索
DDR4 test-2
集合对象值改变NULL值对象
[untitled]
Wireshark packet analysis TCP, FTP
MySQL signale une erreur can 't create table' demo01. TB Étudiant '(errno: 150)
optaplanner学习笔记(一)案例Cloud balance
GetMessage底层机制分析
下载(导出)pdf模板文件(比如:审批单),报错:Invalid nested tag *** found, expected closing tag ***
IPv4 address, subnet mask, gateway
Ubuntu14 install MySQL and configure root account local and remote access
简版拼多多商品数据
Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
Case sharing: basic networking configuration of QinQ
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
采集抖音视频
Test self-study people must see: how to find test items in software testing?
精耕渠道共謀發展 福昕攜手偉仕佳傑開展新產品培訓大會
Redo和Undo的区别
ffmpeg 音频相关命令