Tell me whether to use! (exclamation mark) to check for non-existence of results.

if (!rs.next()) { System.out.println("Π”Π°Π½Π½Ρ‹Π΅ Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½Ρ‹"); } else { System.out.println("Ρ‡Ρ‚ΠΎ-Ρ‚ΠΎ нашли"); } 

    2 answers 2

    Check out the ResultSet documentation:

    Returns: true if the new current row is valid; false if there are no more rows

    Conclusion: quite correct.

      Everything is correct, usually with resultset I use code of the following type:

       while (resultset.next()) { // do something with retrieved data } ΠΈΠ»ΠΈ if (!resultset.next()) { // Π² зависимости ΠΎΡ‚ Π»ΠΎΠ³ΠΈΠΊΠΈ, вмСсто ошибки ΠΌΠΎΠΆΠ½ΠΎ Π²Ρ‹Π²ΠΎΠ΄ΠΈΡ‚ΡŒ сообщСниС Π² Π»ΠΎΠ³ throw new SomeError("No data found"); } // do something with retrieved data