Tell me whether to use! (exclamation mark) to check for non-existence of results.
if (!rs.next()) { System.out.println("ΠΠ°Π½Π½ΡΠ΅ Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½Ρ"); } else { System.out.println("ΡΡΠΎ-ΡΠΎ Π½Π°ΡΠ»ΠΈ"); }
Tell me whether to use! (exclamation mark) to check for non-existence of results.
if (!rs.next()) { System.out.println("ΠΠ°Π½Π½ΡΠ΅ Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½Ρ"); } else { System.out.println("ΡΡΠΎ-ΡΠΎ Π½Π°ΡΠ»ΠΈ"); }
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
Source: https://ru.stackoverflow.com/questions/20912/
All Articles