当前位置:网站首页>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();
边栏推荐
猜你喜欢

大厂音视频职位面试题目--今日头条

How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?

为什么一定要从DevOps走向BizDevOps?

任务:拒绝服务DoS

Optimization of video streaming with repeated requests in the case of unstable easygbs network

Summary of SQL query de duplication statistics methods

AAAI2020: Real-time Scene Text Detection with Differentiable Binarization

奔赴山海之前,毕业季一定要做的那些事情

Test self-study people must see: how to find test items in software testing?

JS 之 常用内置类的使用
随机推荐
Redo和Undo的区别
CMU AI PhD first year summary
Salesmartly has some tricks for Facebook chat!
DDR4 test-2
Methods of finding various limits
Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
GC垃圾回收
Define dichotomy lookup
EasyGBS网络不稳定情况下重复请求视频拉流问题的优化
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
狼人杀攻略:你当我好骗吗,我们相信谁!
【无标题】
Uni app product classification
HLS4ML进入方法
【AI服务器搭建】CUDA环境
Interview question 16.16 Partial sorting - Double finger needling
Instagram 为何从内容共享平台变成营销工具?独立站卖家如何利用该工具?
Introduction and installation of crunch, and making password dictionary with crunch
解决VSCode下载慢或下载失败的问题
Mysql查询结果去除换行