1

I have following Java code

// SELECT
String stringQuery  = "SELECT klucz, itemDATA, itemQTY, itemDUR FROM sellbox WHERE gracz =? "
                    + "ORDER BY czas DESC LIMIT 1";

PreparedStatement statement = this.connection.prepareStatement( stringQuery );
statement.setString( 1, playerName ); 

ResultSet queryResult = statement.executeQuery();
queryResult.first();

How to determine if it returned rows or not?

3 Answers 3

1

You could do:

ResultSet queryResult = statement.executeQuery();
if (queryResult.next()) {
   // process the data
}
Sign up to request clarification or add additional context in comments.

Comments

1

ResultSet provides next() to check the next rows. using ResultSet.first() it self gives false if invalid rows in ResultSet

Reference: ResultSet API

So using the same method, you can verify the rows in ResultSet without using ResultSet.next()

Comments

1

I think this is the way -

ResultSet queryResult = statement.executeQuery();
if(queryResult.next())
  return true;
else
  return false;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.