0

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

2
  • You have stored data in str variable. What is the question about then? Also posting full example source would be helpful. Commented Apr 14, 2013 at 21:36
  • Error I get >Unhandled exception at 0x75a54b32 in camera.exe: Microsoft C++ exception: sql::InvalidArgumentException at memory location 0x0026e014.. Commented Apr 14, 2013 at 21:43

1 Answer 1

2

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();
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so very much! I never thought to even do that even though it's right in the documentation. If I had more rep I'd up vote you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.