Code Room
Code reviewHard
Question
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.
Learn the concepts
void reconcile(Connection conn, long batchId) throws SQLException { conn.setAutoCommit(false); long debits = scalar(conn, "SELECT COALESCE(SUM(amount),0) FROM ledger " + "WHERE batch_id = ? AND kind = 'D'", batchId); long credits = scalar(conn, "SELECT COALESCE(SUM(amount),0) FROM ledger " + "WHERE batch_id = ? AND kind = 'C'", batchId); if (debits != credits) { alert("Imbalance in batch " + batchId); } conn.commit();}Run or narrate your approach, then ask the coach.