/* INSERT TUTORIAL CODE HERE! */
sql::Driver *driver = get_driver_instance();
std::auto_ptr<sql::Connection> con(driver->connect("tcp://127.0.0.1:3307", "root", "pass"));
con->setSchema("mybase");
std::auto_ptr<sql::Statement> stmt(con->createStatement());
//example from dev/mysql site
stmt->execute("DROP TABLE IF EXISTS mcountry");
stmt->execute("DROP PROCEDURE IF EXISTS add_ctry");
stmt->execute("DROP PROCEDURE IF EXISTS getdata");
stmt->execute("CREATE TABLE mcountry(country_id INT)");
stmt->execute("CREATE PROCEDURE add_ctry(IN cname INT) BEGIN INSERT INTO mcountry(country_name) VALUES (cname); END;");
stmt->execute("CREATE PROCEDURE getdata() BEGIN SELECT * FROM mcountry; END;");
stmt->execute("CALL add_ctry(112)");
stmt->execute("CALL add_ctry(323)");
stmt->execute("CALL getdata()");
std::auto_ptr<sql::ResultSet> res;
do{
res.reset(stmt->getResultSet());
while(res->next())
{
cout << "ID: " << res->getInt(1);
}
} while(stmt->getMoreResults());
This works fine, I get result as expected but when i change type from INT
to CHAR - nothing works. I need fetch string data from my table but instead of
good results I get only strange garbage data. Please help me and thanks for any answers..code for fetching string data:
We are going to need to know what your error is. Re-pasting your code inside of code tags would also be helpful, and will likely get you an answer faster.