Il tuo try-with-resources fa close il ResultSet , ma non è questo il vero problema. Devi impostare la Statement prima lo esegui (e preferisci PreparedStatement e vincolare i parametri). Qualcosa come,
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;
}
}
}