0

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;
}

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by qk00001
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.