MySQL connector/C ++ calls the Stored Procedure
(Jinqing's column)
From:
Http://dev.mysql.com/doc/refman/5.6/en/connector-cpp-tutorials-stored-routines-statements.html
Create procedure Test (in country_code char (3), Out country_pop int (11 ))
Begin
Insert into country (CODE) values (country_code );
Select population into country_pop from country where name = 'country _ name ';
Select Code, name, population, continent from country where continent = "Oceania" and population <10000;
Select Code, name, population, continent from country where continent = "Europe" and population <10000;
Select Code, name, population, continent from country where continent = "North America" and population <10000;
End
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 ());
Stmt-> execute ("Call test (\" ATL \ ", @ pop )");
STD: auto_ptr <SQL: resultset> res;
Do {
Res. Reset (stmt-> getresultset ());
While (res-> next ()){
Cout <"Result:" <res-> getstring (1) <Endl;
}
} While (stmt-> getmoreresults ());
STD: auto_ptr <SQL: resultset> res (stmt-> executequery ("select @ pop as _ reply "));
While (res-> next ())
Cout <"population of Uganda:" <res-> getstring ("_ reply") <Endl;