i want to run a loop (may be a do while) to keep getting reults from MSSQL. i have done the do part of the loop. but can find a method that will stop the loop if no results (rows) are returned from mssql. my code is:
String query = "SELECT TOP 1 * FROM tbl_Url WHERE UrlProcessed = 0";
PreparedStatement preparedquery = con.prepareStatement(query);
ResultSet results = preparedquery.executeQuery();
what method should i use to terminate the loop if no rows are returned.is there any method for the Resultset which returns boolean if any result is returned from mssql or a method which returns number of rows. 0 if no rows returned.
First you have to know that the ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set.
To get the number of rows you can try this: