Documentation Home
MySQL Connector/C++ 1.1 Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 284.5Kb
PDF (A4) - 285.8Kb
HTML Download (TGZ) - 54.3Kb
HTML Download (Zip) - 67.6Kb


6.2 Running a Simple Query

To run simple queries, you can use the sql::Statement::execute(), sql::Statement::executeQuery(), and sql::Statement::executeUpdate() methods. Use the method sql::Statement::execute() if your query does not return a result set or if your query returns more than one result set. See the examples directory for more information.

sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
sql::Statement *stmt;

driver = sql::mysql::get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "user", "password");

stmt = con->createStatement();
stmt->execute("USE " EXAMPLE_DB);
stmt->execute("DROP TABLE IF EXISTS test");
stmt->execute("CREATE TABLE test(id INT, label CHAR(1))");
stmt->execute("INSERT INTO test(id, label) VALUES (1, 'a')");

delete stmt;
delete con;
Note

You must free the sql::Statement and sql::Connection objects explicitly using delete.