CSE 344 Section 7
HW6 & Locking
HW6
What is Flights App?
SQL Injection
PreparedStatements
How they work:
String rawQuery = “SELECT * FROM Flights WHERE origin_city = ? AND day_of_month = ?”;
PreparedStatement ps = conn.prepareStatement(rawQuery); // Pre-compiles the query into a PreparedStatement Object
ps.clearParameters(); // Clears parameters from previous use
ps.setString(1, originCity); // Sets the first parameter (the first “?”) to the value of the variable “originCity”
ps.setInt(2, dayOfMonth); // Sets the second parameter (the second “?”) to the value of the variable “dayOfMonth”
ResultSet rs = ps.executeQuery(); // Executes the query and stores the ResultSet in the variable “rs”
ResultSet
// ... continued from previous slide
ResultSet rs = ps.executeQuery();
while (rs.next()) { // check if there is another row and move to the next row
String destCity = rs.getString(“dest_city”); // Gets the value of the attribute “dest_city” for the current row
...
} // When `next` finally returns false, we know we’ve seen every row
rs.close(); // Remember to close the ResultSet
HW6 Notes
HW6 Notes part 2
HW6 Notes part 3
HW6 Demo
Locking
Locking Overview
Remember - locking is for database internal implementation
Database Lock
Table Lock
Predicate Lock
Tuple Lock
Lock Granularity
SQLite!
Less Concurrency
More Concurrency
Binary Locks
2PL with Binary Locks
Lock growing phase
Lock shrinking phase
2PL vs. Strict 2PL
2PL:
Strict 2PL:
2PL vs. Strict 2PL
Invalid reads
Trickled unlock and transaction end
3-Tiered Locking (Shared/Exclusive locks)
All the locks!
Concurrency Control Method | Benefit |
2PL | Ensures conflict serializability |
Strict 2PL | Ensures recovery |
Conservative 2PL (not studied in 344) | Ensures deadlock-free |
Lock Type | Benefit |
Binary Locks | Simplest lock implementation |
Shared/Exclusive Locks | Greater throughput on reads |
Worksheet