Documentation Home
MySQL Connector/C++ Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 249.3Kb
PDF (A4) - 252.8Kb
HTML Download (TGZ) - 52.5Kb
HTML Download (Zip) - 66.8Kb


MySQL Connector/C++ 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:

    shell> 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));
    con->setSchema(database);
    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:

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


User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
Sign Up Login You must be logged in to post a comment.