Use connection.isValid()