Documentation Home
MySQL Connector/C++ Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 0.7Mb
PDF (A4) - 0.7Mb
EPUB - 0.7Mb
HTML Download (TGZ) - 0.6Mb
HTML Download (Zip) - 0.7Mb


7.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.


User Comments
Sign Up Login You must be logged in to post a comment.