当前位置:网站首页>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
}
}
}
边栏推荐
- [leetcode 239] sliding window
- Algorithme leetcode 86. Liste des liens séparés
- 【leetcode 239】滑动窗口
- LeetCode Algorithm 86. 分隔鏈錶
- SQL必需掌握的100个重要知识点:插入数据
- 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
- A man is a Book
- 启明星辰集团运维安全网关(堡垒机)再次夺得榜首!
- promise async和await的方法与使用
- 国产数据库的黄金周期要来了吗?
猜你喜欢

How to analyze native crash through GDB

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

数学(快速幂)

中移OneOS开发板学习入门

R语言查看版本 R包查看版本

科普達人丨漫畫圖解什麼是eRDMA?

国内首批!阿里云云原生数据湖产品通过信通院评测认证

PointDistiller:面向高效紧凑3D检测的结构化知识蒸馏

ESP32-C3入门教程 问题篇⑨——Core 0 panic‘ed (Load access fault). Exception was unhandled. vfprintf.c:1528

Methods and usage of promise async and await
随机推荐
Flutter start from scratch 008 form
单片机 MCU 固件打包脚本软件
SQL必需掌握的100个重要知识点:使用存储过程
dplyr 中的filter报错:Can‘t transform a data frame with duplicate names
国内首批!阿里云云原生数据湖产品通过信通院评测认证
DataX JSON description
LVGL 8.2 menu from a drop-down list
SQL必需掌握的100个重要知识点:使用视图
100 important knowledge points that SQL must master: using subquery
R语言查看版本 R包查看版本
100 important knowledge points that SQL must master: grouping data
CVPR 2022 | 大幅减少零样本学习所需人工标注,马普所和北邮提出富含视觉信息的类别语义嵌入...
EMC-浪涌
建立自己的网站(13)
[applet practice series] Introduction to the registration life cycle of the applet framework page
Train an image classifier demo in pytorch [learning notes]
HMS Core音频编辑服务3D音频技术,助力打造沉浸式听觉盛宴
SQL必需掌握的100个重要知识点:分组数据
Le talent scientifique 丨 dessins animés qu'est - ce qu'erdma?
The life, working principle and application of electrochemical oxygen sensor