Code RoomDatabase connection never returns
MediumPrep Room Coding #1834

Database connection never returns

Code reviewCode quality & reviewMid–Senior~25 min

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.

0:00 of about 25 min
Mark a line and say what kind of problem it is.0 findings
1String lookupFlag(DataSource ds, String key) throws SQLException {
2 Connection conn = ds.getConnection();
3 PreparedStatement ps = conn.prepareStatement(
4 "SELECT value FROM flags WHERE key = ?");
5 ps.setString(1, key);
6 ResultSet rs = ps.executeQuery();
7 if (rs.next()) {
8 String v = rs.getString("value");
9 conn.close();
10 return v;
11 }
12 conn.close();
13 return null;
14}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.