Code RoomUncommitted reads see concurrent changes
HardPrep Room Coding #1839

Uncommitted reads see concurrent changes

Code reviewDatabases & SQLSenior–Staff~28 min

Review this Java (JDBC) reconciliation routine that asserts debits equal credits.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 28 min
Mark a line and say what kind of problem it is.0 findings
1void reconcile(Connection conn, long batchId) throws SQLException {
2 conn.setAutoCommit(false);
3 long debits = scalar(conn,
4 "SELECT COALESCE(SUM(amount),0) FROM ledger "
5 + "WHERE batch_id = ? AND kind = 'D'", batchId);
6 long credits = scalar(conn,
7 "SELECT COALESCE(SUM(amount),0) FROM ledger "
8 + "WHERE batch_id = ? AND kind = 'C'", batchId);
9 if (debits != credits) {
10 alert("Imbalance in batch " + batchId);
11 }
12 conn.commit();
13}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.