Documentation Home
MySQL Connector/C++ 1.1 Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 285.1Kb
PDF (A4) - 286.0Kb

MySQL Connector/C++ 1.1 Developer Guide  /  ...  /  Using a Statement for a Stored Procedure That Returns No Result

7.2.1 Using a Statement for a Stored Procedure That Returns No Result

This example shows how to call a stored procedure that returns no result set.

  1. Make a copy of the tutorial framework code:

    $> cp framework.cpp sp_scenario1.cpp
  2. Add the following code to the try block of the tutorial framework:

    sql::Driver* driver = get_driver_instance();
    std::auto_ptr<sql::Connection> con(driver->connect(url, user, pass));
    std::auto_ptr<sql::Statement> stmt(con->createStatement());
    // We need not check the return value explicitly. If it indicates
    // an error, Connector/C++ generates an exception.
    stmt->execute("CALL add_country('ATL', 'Atlantis', 'North America')");
  3. Compile the program as described in Section 7.1, “Prerequisites and Background Information”.

  4. Run the program:

    $> ./sp_scenario1
  5. Using the mysql command-line client or other suitable program, check the world database to determine that it has been updated correctly. You can use this query:

    mysql> SELECT Code, Name, Continent FROM Country WHERE Code='ATL';
    | Code | Name     | Continent     |
    | ATL  | Atlantis | North America |

The code in this application simply invokes the execute method, passing to it a statement that calls the stored procedure. The procedure itself returns no value, although it is important to note there is always a return value from the CALL statement; this is the execute status. Connector/C++ handles this status for you, so you need not handle it explicitly. If the execute call fails for some reason, it raises an exception that the catch block handles.