DB connection not closed (ARCH4084)
Esta página aún no está disponible en tu idioma.
Key java.performance.db-connection-not-closed · Severity error · Category performance
If a Connection is opened and not closed, it never returns to the pool. Leaked connections quickly drain the pool, and later requests time out waiting for one.
Incorrect
Section titled “Incorrect”public int count() throws SQLException { Connection conn = dataSource.getConnection(); ResultSet rs = conn.createStatement().executeQuery("SELECT count(*) FROM t"); rs.next(); return rs.getInt(1);}Correct
Section titled “Correct”public int count() throws SQLException { try (Connection conn = dataSource.getConnection(); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT count(*) FROM t")) { rs.next(); return rs.getInt(1); }}Open the connection, statement, and result set in try-with-resources so they return to the pool.