MySQL connector/C ++ calls the Stored Procedure

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.