- JDBC 4.0 and Oracle JDeveloper for J2EE Development
- Deepak Vohra
- 344字
- 2021-08-25 18:08:44
Transactions
A transaction is a group of one or more statements run as a unit. If the default value of auto-commit
is set to true
, then each Statement
that would be run represents a transaction. After each statement is run, changes to the database are made with the auto-commit
set to true
. Set the auto-commit
to false, if a developer requires a group of statements to be run together. Changes to the database are not made till each of the statement has run. If auto-commit
is set to false
, the changes to the database are committed with the commit()
method. The commit()
method commits the SQL statements run after the previous commit to the database was made. The group of statements run between two consecutive commits to the database represents a transaction. The rollback()
method rolls back the changes made in the current transaction. A transaction may be required to be rolled back, if an error or a SQLException
is generated.
While one transaction is modifying a database table, another transaction could be reading from the same table. The type of read can be dirty-read, a non-repeatable read, or a phantom read. A dirty-read occurs when a row has been modified by a transaction, but has not been committed, and is being read by a different transaction. If the transaction that modifies the row rolls back the transaction, then the value retrieved by the second transaction would be erroneous. A non-repeatable transaction occurs when one transaction reads a row while the other transaction modifies it. The first transaction re-reads the row obtaining a different value. A phantom read occurs when one transaction retrieves a result set with a WHERE
condition, while the other transaction adds a row that meets the WHERE
condition. The first transaction re-runs to generate a result set that has an additional row. The default transaction level can be obtained with the getTransactionLevel()
method:
int transactionLevel=connection. getTransactionIsolation();
The different transaction isolation levels are listed in following table:

The transaction isolation level can be set with the setTransactionIsolation(int level)
method:
connection.setTransactionIsolation(level);
- 中文版CorelDRAW X7基礎(chǔ)培訓(xùn)教程(移動(dòng)學(xué)習(xí)版)
- 圖像處理基礎(chǔ)教程(Photoshop CS5)(第2版)
- 好的PPT會(huì)說話:如何打造完美幻燈片
- 品悟:Alias 2014+Showcase產(chǎn)品可視化造型與渲染
- After Effects CC 2019 影視后期特效合成案例教程
- 中文版Illustrator CC 2018基礎(chǔ)培訓(xùn)教程
- 皮膚鏡圖像分析與識(shí)別
- Photoshop 2024從入門到精通
- Unity 2020游戲開發(fā)快速上手
- Service Oriented Java Business Integration
- Photoshop+CorelDRAW 字體設(shè)計(jì)與創(chuàng)意:草圖/實(shí)現(xiàn)/包裝(微課版)
- 攝影師的后期必修課(調(diào)色篇)
- After Effects 2023實(shí)訓(xùn)教程
- 動(dòng)畫制作基礎(chǔ)(項(xiàng)目教學(xué)版)
- Cassandra High Performance Cookbook