Question

So I downloaded the c++/mysql connector from http://dev.mysql.com/downloads/connector/cpp/
Now I want to store data that I've retrieved from the database to a variable. This is as far as I've gotten.

string str;
/////////////////////////////////get data from database////////////////////////////////////////////////////////
  sql::Driver *driver;
  sql::Connection *con;
  sql::Statement *stmt;
  sql::ResultSet *res;

  /* Create a connection */
  driver = get_driver_instance();
  con = driver->connect("tcp://127.0.0.1:3306", "root", "");
  /* Connect to the MySQL test database */
  con->setSchema("awesome");

  stmt= con->createStatement();

      res = stmt->executeQuery(

"SELECT * FROM master where choice='Y'");

/////////////////////////////Store it somewhere/////////////////////////////// 
          str= res->getString("rfid");

Any and all help is welcomed

Était-ce utile?

La solution

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();
  }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top