previous | start | next

Answers

  1. result.hasNext(). If there is at least one result, then hasNext returns true.
  2. ResultSet result = stat.executeQuery(
          "SELECT COUNT(*) FROM Customer WHERE State = 'HI'");
    result.next();
    int count = result.getInt(1);
    Note that the following alternative is significantly slower if there are many such customers.
    ResultSet result = stat.executeQuery(
          "SELECT * FROM Customer WHERE State = 'HI'");
    while (result.next()) count++; // Inefficient


previous | start | next