当前位置:网站首页>JDBC transaction commit case
JDBC transaction commit case
2022-06-27 07:21:00 【Qingyun ing】
import com.mysql.jdbc.Driver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class JDBCDemo {
public static void main(String[] args) throws Exception {
//1 Get the connection
String url = "jdbc:mysql://IP:Port/db_name";
String username = "username ";
String password = "password ";
Connection conn = DriverManager.getConnection(url, username, password);
//2 sql sentence
String sql = "update account set age=18 where id=1";
//3 Access to perform sql The object of
Statement stmt = conn.createStatement();
try {
// Open transaction
conn.setAutoCommit(false);
//4 perform sql
int count = stmt.executeUpdate(sql);
//5 Print processing results
System.out.println(count);
// Commit transaction
conn.commit();
} catch (Exception e) {
conn.rollback();
e.printStackTrace();
}
//6 Release resources
stmt.close();
conn.close();
}
}
边栏推荐
- [graduation season] graduation is the new beginning of your life journey. Are you ready
- 2022 cisp-pte (I) document contains
- One person manages 1000 servers? This automatic operation and maintenance tool must be mastered
- 【Kevin三连弹之三】Rust真的比C慢吗?进一步分析queen微测评
- From 5 seconds to 1 second, the system flies
- Optimistic and pessimistic affairs
- Tar: /usr/local: cannot find tar in the Archive: due to the previous error, it will exit in the last error state
- How torch.gather works
- Hutool symmetric encryption
- window右键管理
猜你喜欢

聊聊领域驱动设计

Vs how to configure opencv? 2022vs configuration opencv details (multiple pictures)

【OpenAirInterface5g】RRC NR解析之RrcSetupComplete

2022 CISP-PTE(一)文件包含

用XGBoost迭代读取数据集
[email protected][2389:1: columnNameTypeOrConstraint : ( ( tableConstraint ) | ( columnNameT"/>NoViableAltException([email protected][2389:1: columnNameTypeOrConstraint : ( ( tableConstraint ) | ( columnNameT

Interviewer: do you have any plan to request a lot of data that does not exist in redis to destroy the database?

From 5 seconds to 1 second, the system flies

thrift

程序人生 - 程序员三十五岁瓶颈你怎么看?
随机推荐
JDBC读取Mysql数据列表
多表联查--07--- Hash join
Rust中的Pin详解
The interviewer of a large front-line factory asked: do you really understand e-commerce order development?
从5秒优化到1秒,系统飞起来了...
2022 CISP-PTE(二)SQL注入
uview的安装和功能
Date database date strings are converted to and from each other
Machine learning
Interviewer: please introduce cache penetration, cache null value, cache avalanche and cache breakdown, which are easy to understand
攻防演习防御体系构建之第一篇之介绍和防守的四个阶段
【软件工程】山东大学软件工程复习提纲
jupyter notebook文件目录
Easyexcel: read Excel data into the list set
聊聊领域驱动设计
一個人管理1000臺服務器?這款自動化運維工具一定要掌握
tracepoint
poi导出excle
Use uview to enable tabbar to display the corresponding number of tabbars according to permissions
Self test in the second week of major 4