sql >> Base de Datos >  >> RDS >> Oracle

Excepción Java SQL:conjunto de resultados cerrado:siguiente aunque ni la conexión ni el conjunto de resultados se cierran

Tu try-with-resources hace close el ResultSet , pero ese no es el verdadero problema. Debe configurar la Statement antes lo ejecuta (y prefiere PreparedStatement y enlazar parámetros). Algo como,

public Integer findByName(String name) throws SQLException {
    String sql = "select id from artists where name=?";
    Connection con = Database.getConnection();
    try (PreparedStatement stmt = con.prepareStatement(sql)) {
        stmt.setString(1, name);
        try (ResultSet rs = stmt.executeQuery()) {
            return rs.next() ? rs.getInt(1) : null;
        }
    }
}