当前位置:网站首页>Database transactions
Database transactions
2022-06-30 11:29:00 【TYUT ljk】
Business
Basic introduction
- Concept : If a business operation contains multiple steps , Managed by affairs , So these operations are either successful at the same time , Or fail at the same time
- operation
(1) Open transaction :start transaction
(2) Roll back :rollback
(3) Submit :commit - Transaction submission method
(1) Automatic submission
mysql It's automatic submission
One DML( Additions and deletions ) Statement will automatically commit a transaction
(2) Manual submission
Oracle The default is manual submission
You need to start the transaction first , Submit again
(3) Modify the default submission method
View the default transaction submission method :SELECT @@autocommit
1 Represents automatic submission ,0 Indicates manual submission
Modify the default submission method :SET @@autocommit = 0
In this case, the modification operation is performed when the submission operation is not performed , It's only temporary , Will not affect the actual database
Four characteristics
- Atomicity : Is the smallest divisible unit , Or at the same time , Or fail at the same time
- persistence : When a transaction is committed or rolled back , The database will persist the data
- Isolation, : Multiple transactions are independent of each other
- Uniformity : Before and after transaction operation , The total amount of data remains the same
The isolation level of the transaction
- Concept : Multiple transactions are independent of each other , But if multiple transactions operate on the same batch of data , It will cause some problems , Setting different isolation levels can solve these problems
- Existing problems :
(1) Dirty reading : One transaction reads uncommitted data from another transaction
(2) It can't be read repeatedly ( Virtual reading ): In the same transaction , The data read twice is not the same
(3) Fantasy reading : A transaction operation (DML) All records in the data sheet , Add a piece of data to another transaction , Then the first transaction cannot query its own modification - Isolation level
(1)read uncommitted: Read uncommitted
A problem : Dirty reading , It can't be read repeatedly , Fantasy reading
(2)read committed: Read submitted (Oracle Default )
A problem : It can't be read repeatedly , Fantasy reading
(3)repeatable read: Repeatable (Mysql Default )
A problem : Fantasy reading
(4)serializable: Serialization
Can solve all the problems - Be careful : Isolation level from small to large , Security is getting higher and higher , But the efficiency is getting lower
- Query isolation level
select @@tx_isolation - Set isolation level
set global transaction isolation level Level string
JDBC Manage affairs
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class JDBCDemo {
public static void main(String[] args) throws SQLException {
Connection conn = null;
try{
conn = JDBCUtils.getConnect();
// Open transaction
conn.setAutoCommit(false);
//sql perform
// Commit transaction
conn.commit();
} catch (Exception e) {
e.printStackTrace();
// Something goes wrong , Roll back
conn.rollback();
}finally {
// close resource
}
}
}
边栏推荐
- 【IC5000教程】-01-使用daqIDEA图形化debug调试C代码
- Wireguard simple configuration
- SQL必需掌握的100个重要知识点:使用存储过程
- 启明星辰集团运维安全网关(堡垒机)再次夺得榜首!
- 10天学会flutter DAY10 flutter 玩转 动画与打包
- Use of switch statement in go language learning
- “新数科技”完成数千万元A+轮融资,造一体化智能数据库云管理平台
- HMS Core音频编辑服务3D音频技术,助力打造沉浸式听觉盛宴
- SQL必需掌握的100个重要知识点:创建和操纵表
- 100 important knowledge points that SQL must master: summary data
猜你喜欢

Discussion on the essence of "FPGA mining" from open source projects

对象映射 - Mapping.Mapster

【IC5000教程】-01-使用daqIDEA图形化debug调试C代码

Le talent scientifique 丨 dessins animés qu'est - ce qu'erdma?

Multiparty Cardinality Testing for Threshold Private Set-2021:解读

Alibaba cloud lifeifei: China's cloud database has taken the lead in many mainstream technological innovations abroad

R language de duplication operation unique duplicate filter

孔松(信通院)-数字化时代云安全能力建设及趋势
![[xi'anjiaotonguniversity] information sharing of the first and second postgraduate entrance examinations](/img/06/df5a64441814c9ecfa2f039318496e.jpg)
[xi'anjiaotonguniversity] information sharing of the first and second postgraduate entrance examinations

The operation and maintenance security gateway (Fortress machine) of Qiming star group once again won the first place!
随机推荐
Discussion on the essence of "FPGA mining" from open source projects
揭秘得物客服IM全链路通信过程
LeetCode Algorithm 86. 分隔鏈錶
100 important knowledge points that SQL must master: using stored procedures
Go language defer
建立自己的网站(13)
EMC-浪涌
Lvgl 8.2 picture scaling and rotation
8行代码实现快速排序,简单易懂图解!
盘点那些具有特色的写作软件
Livedata source code appreciation III - frequently asked questions
Wireguard simple configuration
The reasoning delay on iphone12 is only 1.6 MS! Snap et al. Analyzed the transformer structure latency in detail, and used NAS to find out the efficient network structure of mobile devices
100 important knowledge points that SQL must master: using table aliases
ESP32-C3入门教程 问题篇⑨——Core 0 panic‘ed (Load access fault). Exception was unhandled. vfprintf.c:1528
The latest collection of arouter problems
SQL必需掌握的100个重要知识点:使用视图
孔松(信通院)-数字化时代云安全能力建设及趋势
Retest the cloud native database performance: polardb is still the strongest, while tdsql-c and gaussdb have little change
Esp32-c3 introductory tutorial basic part ⑫ - mass production burning device configuration and serial number, NVS partition confirmation, NVS partition generation program, CSV to bin