How should I check for an empty resultset using datastax java cassandra driver?
Suppose I'm executing the following query "SELECT * FROM my_table WHERE mykey=something"
there is a great chance that the query will not be matched. The following code does not work:
if (rs != null)
rs.one().getString("some_column");
You were pretty close, the correct solution is:
Row r = rs.one();
if (r != null)
r.getString("some_column");
The driver will always return a result set, whether or not there were any returned results. The documentation for one() states that if no rows were returned rs.one() returns null.
You can also use getAvailableWithoutFetching() which returns the number of rows in the result set without fetching more rows. Since pageSize has to be >= 1, you can be assured if there are is at least 1 row this will always return a value greater than 0.
You can also check the value of rs.isExhausted()
in order to determine whether or not there is additional data in the result set...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With