Code Room
Code reviewMedium
Question
Review this Java method that reads a config value from a pooled DataSource.
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
String lookupFlag(DataSource ds, String key) throws SQLException { Connection conn = ds.getConnection(); PreparedStatement ps = conn.prepareStatement( "SELECT value FROM flags WHERE key = ?"); ps.setString(1, key); ResultSet rs = ps.executeQuery(); if (rs.next()) { String v = rs.getString("value"); conn.close(); return v; } conn.close(); return null;}Run or narrate your approach, then ask the coach.