当前位置:网站首页>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 correctly use vertx to operate redis (3.9.4 with source code analysis)
- DDR4 test-2
- Simplified pinduoduo product data
- Wechat applet navigator has a shadow after clicking. Remove the shadow effect of navigator
- 精耕渠道共謀發展 福昕攜手偉仕佳傑開展新產品培訓大會
- 狼人杀攻略:你当我好骗吗,我们相信谁!
- ffmpeg 音频相关命令
- JS ternary expression complex condition judgment
- JVM内存模型
- 正则表达式=Regex=regular expression
猜你喜欢
随机推荐
Shell高级进阶
JS的Proxy
Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
H264 encoding profile & level control
商业智能BI开发和报表开发有什么本质区别?
Solution and summary of Nacos startup failure
brpc理解
Ffmpeg common commands (2)
GB28181之SIP协议
Transaction isolation level gap lock deadlock
Methods of finding various limits
1592 例题1 国王(Sgu223 LOJ10170 LUOGU1896 提高+/省选-) 暴力思考 状压DP 01背包
What must be done in graduation season before going to Shanhai
狼人杀攻略:你当我好骗吗,我们相信谁!
Thesis reading [distinctive late semantic graph for video capturing]
类加载机制
Analysis of GetMessage underlying mechanism
New window open page -window open
Live HLS protocol
Wechat applet navigator has a shadow after clicking. Remove the shadow effect of navigator