sql::ResultSet *res = stmt->executeQuery("SELECT * FROM employees"); sql::QueryResult_AutoPtr result(res); int rowCount = result->getRowCount(); cout << "Number of rows in the result set: " << rowCount << endl;
sql::ResultSet *res = stmt->executeQuery("SELECT COUNT(*) FROM employees"); sql::QueryResult_AutoPtr result(res); int rowCount = result->getRowCount(); cout << "Number of rows in the result set: " << rowCount << endl;In this example, we create a query to retrieve a count of all the employees from the database using an SQL SELECT statement with the COUNT(*) function. We then create a QueryResult_AutoPtr object and pass it the ResultSet object returned by the executeQuery() function call. Next, we call the getRowCount() function to retrieve the number of rows returned by the query. Package library: The code examples use the MySQL Connector/C++ package library.