当前位置:网站首页>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
}
}
}
边栏推荐
- 线代(高斯消元法、线性基)
- LVGL 8.2 menu from a drop-down list
- Le talent scientifique 丨 dessins animés qu'est - ce qu'erdma?
- 8 lines of code to achieve quick sorting, easy to understand illustrations!
- H3C switch emptying configuration
- SQL必需掌握的100个重要知识点:更新和删除数据
- Digitalization is not a trial, but a wading out of "Xingzhi Digital China" × History of Foxconn
- R语言查看版本 R包查看版本
- Oracle netsuite helps TCM bio understand data changes and make business development more flexible
- Line generation (Gauss elimination method, linear basis)
猜你喜欢

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

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

CVPR 2022 | 大幅减少零样本学习所需人工标注,马普所和北邮提出富含视觉信息的类别语义嵌入...

Handler-源码分析

Wechat Emoji is written into the judgment, and every Emoji you send may become evidence in court

阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外

Record the memory leak of viewpager + recyclerview once

The life, working principle and application of electrochemical oxygen sensor

10 reasons for system performance failure

优惠券种类那么多,先区分清楚再薅羊毛!
随机推荐
What is a wechat applet that will open the door of the applet
ESP32-C3入门教程 基础篇⑪——Non-Volatile Storage (NVS) 非易失性存储参数的读写
100 important knowledge points that SQL must master: using stored procedures
中移OneOS开发板学习入门
SQL必需掌握的100个重要知识点:分组数据
数学(快速幂)
SQL必需掌握的100个重要知识点:使用子查询
考研这些“不靠谱”的经验有多害人?
R语言查看版本 R包查看版本
100 important knowledge points that SQL must master: updating and deleting data
LVGL 8.2 menu from a drop-down list
AMS源码解析
Dameng data rushes to the scientific innovation board, or becomes the "first share of domestic database" in the A-share market
ESP32-C3入门教程 IoT篇⑤——阿里云 物联网平台 EspAliYun RGB LED 实战之批量生产的解决方案
从开源项目探讨“FPGA挖矿”的本质
国产数据库的黄金周期要来了吗?
8行代码实现快速排序,简单易懂图解!
Methods and usage of promise async and await
【无标题】
Record the memory leak of viewpager + recyclerview once