The SQL statement in your first attempt was better. Anf the while loop in your new attempt is better.
Your new SQL query is invalid. You did not give a table name. (you need to select <from table>). And if you write a where clause in your query (justl like you did in your first example), you only get records where the city is london, and you don't have to perform the extra check in the while loop.
And follow Paul's advise: close your resources after use, and use a PreparedStatement.