Hi guys, I am working on progamm about reading some words in MySQL then display the results during run time command.But my code keep giving some MySQL errors about I can't read it.
Am I making some mistakes with sequence?
I am pretty new in C++.
//---------------here is code
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("localhost", "root", "qwerty");
/* Connect to the MySQL menagerie database */
con->setSchema("menagerie");
stmt = con->createStatement();
stmt->execute("set names \'GBK\'");
string str;
string str1;
cout << "Enter a sentence: ";
getline(cin, str, '\n');
cout << endl;
string::iterator It = str.begin();[I][B]//------------till here work well but will not do the query part down below at all[/B][/I]
while ( It != str.end() )
{
if ( *It == ' ' )
{
*It = '\n';
str1=*It++;
cout<<str1;
}
res=stmt->executeQuery("select * from test2 where english='"+str1+"'");
while(res->next ())
{
cout<<"Result: "<<res->getString(2);
}
}
cout << endl;
delete res;
delete stmt;
delete con;
}