现在的位置: 首页 > 综合 > 正文

数据库 4 种隔离级别

2013年10月04日 ⁄ 综合 ⁄ 共 1513字 ⁄ 字号 评论关闭

int java.sql.Connection.TRANSACTION_SERIALIZABLE = 8 [0x8]隔离性最强

dirty readsnon-repeatable
reads
 and phantom reads are
prevented. This level includes the prohibitions in 
TRANSACTION_REPEATABLE_READ and further prohibits the
situation where one transaction reads all rows that satisfy a 
WHERE condition, a second transaction inserts a
row that satisfies that 
WHERE condition, and the first transaction rereads for the same condition, retrieving the
additional "phantom" row in the second read.
(即,COMMIT的所有数据看不到 ,包括 更新/插入/删除 的row统统看不到

 

int java.sql.Connection.TRANSACTION_REPEATABLE_READ = 4 [0x4] 隔离性次强

dirty reads and non-repeatable
reads
 are prevented; phantom reads can
occur. This level prohibits a transaction from reading a row with uncommitted changes in it, and it also 
prohibits the
situation where one transaction reads a row, a second transaction alters the row, and the first transaction rereads the row, getting different values the second
time (a "non-repeatable read").(即,虽然已经 COMMIT 了,依然有一些数据是 看不到 的:  alters  的row看不到。注意:新 
插入/删除 的row是可以看到

 

int java.sql.Connection.TRANSACTION_READ_COMMITTED = 2 [0x2]

dirty reads are prevented; non-repeatable
reads
 and phantom reads can
occur. This level only 
prohibits a transaction from reading a row with uncommitted
changes in it.(COMMIT 后的数据统统可以看到

 

int java.sql.Connection.TRANSACTION_READ_UNCOMMITTED = 1 [0x1]压根就隔离

dirty readsnon-repeatable
reads
 and phantom reads can
occur. This level allows a row changed by one transaction to be read by another transaction before any changes in that row have been committed (a "dirty read"). If any of the changes are rolled back, the second transaction will have retrieved an invalid row.

抱歉!评论已关闭.