Code Room
Code reviewMediumcr-g199
Subject Connection leakLevel Mid–Senior~25 minCommon in Code quality & review interviewsIndustries Software development

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.

Talk through your review
Code to reviewjava
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.