While it is not that easy to guess what is happening without rest of the code and database data, following code should help to at least get better understanding on what went wrong:
try
{
while (res->next())
{
str= res->getString("rfid");
}
}
catch (std::exception &e)
{
std::cerr << e.what();
}