当前位置:网站首页>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();
边栏推荐
- 大厂音视频职位面试题目--今日头条
- 奔赴山海之前,毕业季一定要做的那些事情
- Interview question 16.16 Partial sorting - Double finger needling
- ddr4测试-2
- Solidity - contract structure - error - ^0.8.4 NEW
- mysql 報錯 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
- Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
- 如何正确使用Vertx操作Redis(3.9.4带源码分析)
- 宝,运维100+服务器很头疼怎么办?用行云管家!
- 使用 Kibana Timelion 进行时间序列分析
猜你喜欢

正则表达式=Regex=regular expression

ddr4测试-2

AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
![Thesis reading [distinctive late semantic graph for video capturing]](/img/d4/4f84a73a9127fa87bb0a74c4655d15.png)
Thesis reading [distinctive late semantic graph for video capturing]

音视频、编解码相关电子书、小工具,打包奉送!
![[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function](/img/1e/bed6a761f07c052e43b1e3b1701760.png)
[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function

GB28181之SIP协议

Task: denial of service DOS

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

Native JS creates a calendar - supports mouse wheel scrolling to select months - and can be ported to any framework
随机推荐
Uni app wechat applet one click login to obtain permission function
JS的Proxy
Download (export) PDF template file (such as approval form), and report error: invalid nested tag * * * found, expected closing tag***
Analysis of GetMessage underlying mechanism
Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
Instagram 为何从内容共享平台变成营销工具?独立站卖家如何利用该工具?
大厂音视频职位面试题目--今日头条
Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
2022/6/8-2022/6/12
118. Yanghui triangle
通过js实现金字塔(星号金字塔,回文对称数字金字塔)
CMU AI PhD 第一年总结
Test self-study people must see: how to find test items in software testing?
宝,运维100+服务器很头疼怎么办?用行云管家!
【AI服务器搭建】CUDA环境
事务隔离级别 gap锁 死锁
Regular expression =regex=regular expression
Introduction to relevant processes and functions of wechat official account development
Simplified pinduoduo product data
The use of subplot function in MATLAB