Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
User : root
Database Name: RAIL
Table schema is : try(name varchar[30], id int)
Procedure name: call_id
Procedure body: SELECT * FROM try WHERE id < 13;

I want to make a C/C++ program on Linux(Ubuntu 12.04).
In this program a want to call procedure(above mentioned) and Display Its result.

Please help me...
Posted

1 solution

Hello Singh_iitb,

First of all you will require a driver. You can obtain MySQL Connector for C++ from here[^]. The instructions for installing this connector can be found here[^].

The examples directory of the MySQL Connector for C++ contains many example program which should get you started. Below code snippet shows a small sample demonstrating how you can execute a simple SQLs.
C++
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;

Regards,
 
Share this answer
 
Comments
nv3 9-Jul-13 3:07am    
My 5.
Prasad Khandekar 9-Jul-13 3:14am    
Thank's.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900