To repeat: 1. Create procedure: create procedure p1(in username varchar(192)) begin declare temphost varchar(16); declare hosts varchar(255); declare nomore int; declare curuser cursor for select host from mysql.user where user=username; declare continue handler for not found set nomore=1; set hosts=''; set nomore=0; open curuser; fetch curuser into temphost; while nomore <> 1 do set hosts = concat(hosts, temphost); fetch curuser into temphost; if nomore <> 1 then set hosts = concat(hosts, "\n"); end if; end while; close curuser; if hosts <> '' then select user, hosts from mysql.user where user=username; end if; end 2. Compile and run following code: #include #include #include #include #include #include "mysql_connection.h" #include #include #include #include #include #define EXAMPLE_HOST "tcp://127.0.0.1:13000" #define EXAMPLE_USER "root" #define EXAMPLE_PASS "" #define EXAMPLE_DB "test" using namespace std; int main(int argc, const char **argv) { string url(argc >= 2 ? argv[1] : EXAMPLE_HOST); const string user(argc >= 3 ? argv[2] : EXAMPLE_USER); const string pass(argc >= 4 ? argv[3] : EXAMPLE_PASS); const string database(argc >= 5 ? argv[4] : EXAMPLE_DB); std::auto_ptr< sql::PreparedStatement > pstmt; std::auto_ptr< sql::ResultSet > res; sql::Driver* driver = get_driver_instance(); std::auto_ptr con(driver->connect(url, user, pass)); con->setSchema(database); //std::auto_ptr stmt(con->createStatement()); pstmt.reset(con->prepareStatement("CALL p1('root')")); pstmt->executeQuery(); res.reset(pstmt->getResultSet()); if (res->next()) { cout << res->getString("hosts"); } cout << "Done." << endl; return EXIT_SUCCESS; } 3. Procedure without cursor that works: create procedure p4(in username varchar(192)) begin declare temphost varchar(16); declare hosts varchar(255); declare nomore int; declare curuser cursor for select host from mysql.user where user=username; declare continue handler for not found set nomore=1; set hosts='foo'; set nomore=0; if hosts <> '' then select user, hosts from mysql.user where user=username; end if; end