Today's mission
? Develop a transfer case using the MVC design pattern
Teaching navigation
Teaching objectives
Mastering the design pattern of JSP
Understanding MySQL's transaction management
Mastering the transaction management of JDBC
Management of transactions is done using dbutils
Teaching methods
Case-driven approach
1.1 Previous lesson Content review:
Jsp:
1.2.2.2 Step Analysis:
"Step One": Create a page:
Step two: Import JDBC-related jar packages and tool classes.
Step three: Create the package structure.
"Step four": Submit to Servlet-->service-->dao
"Step Five": Page Jump:
1.2.3 Code implementation: 1.2.3.1 Preparation work:
1.2.3.2 Code implementation:
1.2.3.3 Dbutils for transaction management:
? No transaction management:
? There are transaction management:
1.2.4 Summary: 1.2.4.1 transaction Features:
? Atomicity: Emphasizing the indivisibility of affairs.
? Consistency: It is emphasized that the integrity of the data should be consistent before and after the execution of the transaction.
? Isolation: The execution of a transaction should not be disturbed by other transactions.
? Persistence: Once a transaction ends (commits/rolls back) The data is persisted to the database.
1.2.4.2 if the isolation of transactions is not considered, some security issues are raised:
? A class of reading problems:
- Dirty reads: One transaction reads data that has not yet been committed by another transaction.
- Non-REPEATABLE READ: One transaction reads the data of an update that has been committed by another transaction, causing inconsistencies in the results of multiple queries in the current transaction.
- Virtual read/Phantom read: One transaction reads the insert data that has been committed by another transaction, resulting in inconsistent query results multiple times in the current transaction.
? A class of write questions:
- Two types of missing updates are thrown:
1.2.4.3 solve the read problem raised:
To set the isolation level of a transaction:
- READ UNCOMMITTED: Unread. Dirty read, non-repeatable read, virtual read can occur.
- Read Committed: Reads committed. Avoid dirty reads. But non-repeatable reads and false reads can occur.
- REPEATABLE READ: repeatable reading. Avoid dirty reading, not repeatable read. But there is a possibility of a false reading.
- Serializable: serialized. Avoid dirty reading, non-repeatable reading, and virtual reading.
MySQL Isolation level: REPEATABLE READ Oracle Isolation LEVEL: Read Committed
1.2.4.4 shows the occurrence of dirty reads:
? Open two windows respectively: A, B
? View the isolation level of two Windows separately: SELECT @ @tx_isolation;
? The isolation level for the Set a window is: READ UNCOMMITTED:
- Set session transaction ISOLATION level READ UNCOMMITTED;
? To open a transaction in two windows, respectively:
- Start transaction;
? To complete the transfer operation in window B:
- Update account Set money = money-1000 WHERE name = ' Jason ';
- Update account Set Money = money + + WHERE name = ' chicken sister ';
? Query data in a window: (Money has been to the account---dirty Read)
- SELECT * from Account; --A transaction read the data that the B transaction has not yet submitted.
1.2.4.5 demo avoids dirty reads, non-repeatable reads occur
? Open two windows respectively: A, B
? View the isolation level of two Windows separately: SELECT @ @tx_isolation;
? The isolation level for the Set a window is: Read Committed:
- Set session transaction Isolation level Read Committed;
? To open a transaction in two windows, respectively:
- Start transaction;
? To complete the transfer operation in window B:
- Update account Set money = money-1000 WHERE name = ' Jason ';
- Update account Set Money = money + + WHERE name = ' chicken sister ';
? To query in a window:
- SELECT * from Account; --Avoid dirty reading.
? Commit the transaction in the b window:
- Commit
? Query again in the A window:
- SELECT * from Account; --the transfer was successful. (Non-REPEATABLE READ: One transaction reads data from an update that has been committed in another transaction, causing inconsistencies in multiple query results.)
1.2.4.6 demo to avoid non-repeatable reads:
? Open two windows respectively: A, B
? View the isolation level of two Windows separately: SELECT @ @tx_isolation;
? The isolation level for the Set a window is: Repeatable READ:
- Set session transaction ISOLATION level repeatable read;
? To open a transaction in two windows, respectively:
- Start transaction;
? To complete the transfer operation in window B:
- Update account Set money = money-1000 WHERE name = ' Jason ';
- Update account Set Money = money + + WHERE name = ' chicken sister ';
? In a window query:
- SELECT * from Account; --the transfer was unsuccessful: avoid dirty reading.
? Commit the transaction in the b window:
- Commit
? Query again in the A window:
- SELECT * from Account; --the transfer was unsuccessful: avoid non-repeatable reading.
1.2.4.7 demo To avoid the occurrence of virtual reads:
? Open two windows respectively: A, B
? View the isolation level of two Windows separately: SELECT @ @tx_isolation;
? The isolation level for the Set a window is: Serializable:
- Set session transaction isolation level serializable;
? Open the transaction separately in a, B, two windows:
- Start transaction;
? Complete an insert operation in the b window:
- Insert into account values (null, ' Miss Wang ', 10000);
? To do a query in a create:
- SELECT * from Account; --no results were queried.
? Commit the transaction in the b window:
- Commit --a window will display the data immediately.
13th Chapter WEB13-JSP Mode &JDBC Advanced Chapter