JDBC transaction level, please learn more

Source: Internet
Author: User

JDBC transaction level
Transactions are separated by locks to solve the problem related to "multiple threads request the same data. Most mainstream databases support different types of locks. Therefore, JDBC APIs support different types of transactions, which are assigned or determined by the Connection object. The following transaction levels can be obtained in the jdbc api:
TRANSACTION_NONE indicates that transactions are not supported.
TRANSACTION_READ_UNCOMMITTED indicates that the change of another transaction can be seen before the transaction is committed. In this way, dirty reads, non-repeated reads, and virtual reads are allowed.
TRANSACTION_READ_COMMITTED indicates that uncommitted data cannot be read. This level still allows non-repeated reads and virtual reads.
TRANSACTION_REPEATABLE_READ indicates that the transaction can read the same data again without failure, but the virtual read will still appear.
TRANSACTION_SERIALIZABLE is the highest transaction level, which prevents dirty reads, non-repeated reads, and virtual reads.
You may wonder why not all transactions run in the TRANSACTION_SERIALIZABLE mode to ensure the highest degree of data integrity? The problem is that the higher the transaction protection level, the higher the performance loss, similar to the problem related to processing multi-threaded programming.
Assuming that your database and JDBC driver support this feature, you can explicitly set the transaction level you want to assign a Connection object:
Con. setTransactionLevel (TRANSACTION_SERIALIZABLE );
You can also determine the level of the current transaction:
If (con. getTransactionLevel () = TRANSACTION_SERIALIZABLE)
System. out. println ("Highest Transaction Level in operation .");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.