Как исправить странную проблему синтаксиса при использовании функции execute? - PullRequest
0 голосов
/ 02 января 2019

Я обнаружил ошибку при попытке использовать функцию с именем execute для использования одной базы данных. Информация показывает мне, что это о синтаксисе, но я так не думаю. Ниже приведен мой критический код и важная информация об ошибке.

У вас ошибка в синтаксисе SQL; проверьте руководство, соответствующее вашей версии сервера MySQL, для правильного синтаксиса, чтобы использовать рядом с 'u' в строке 1

#include <stdlib.h>
#include <iostream>

/*
  Include directly the different
  headers from cppconn/ and mysql_driver.h + mysql_util.h
  (and mysql_connection.h). This will reduce your build time!
*/


#include<string>

#include "mysql_connection.h"

#include <mysql_driver.h>

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
using namespace sql;

int main()
{

    try {
  sql::mysql::MySQL_Driver driver;
  cout<<" driver "<<endl;
  sql::Connection *con = NULL;
  cout<<" con"<<endl;
  sql::Statement *stmt;
  cout<<" stmt"<<endl;
  sql::ResultSet *res;
  cout<<" res"<<endl;
  /* Create a connection */
  //driver = sql::mysql::MySQL_Driver::MySQL_Driver();

  SQLString ip_port("localhost:3306");
  cout<<"some debug string"<<endl;
  SQLString user("debian-sys-maint");
  SQLString password("fTlykRye1LwttC8f");
  con = driver.connect(ip_port, user, password);
  assert(con!=NULL);
  cout<<" root"<<endl;
  /* Connect to the MySQL test database */

  SQLString schema("account");

  //con->setSchema(schema); 
  cout<<" table"<<endl;
  stmt = con->createStatement();
  cout<<" table*2"<<endl;
  assert(stmt!=NULL);
  SQLString db("use account");
  stmt->execute(db);
  res = stmt->executeQuery("SELECT * from user");
  while (res->next()) {
    cout << "\t... MySQL replies: ";
    /* Access column data by alias or column name */
    cout << res->getString("name") << endl;
    cout << "\t... MySQL says it again: ";
    /* Access column data by numeric offset, 1 is the first column */
    cout << res->getString("password") << endl;
  }
  delete res;
  delete stmt;
  delete con;

} catch (sql::SQLException &e) {
  cout << "# ERR: SQLException in " << __FILE__;
  cout << "(" << __FUNCTION__ << ") on line "<<endl;
  cout << "# ERR: " << e.what();
  cout << " (MySQL error code: " << e.getErrorCode();
  cout << ", SQLState: " << e.getSQLState() << " )" << endl;
  cout<<"\n";

}

cout << endl;

return EXIT_SUCCESS;
}

Меня смутило то, почему информация была не о предложении «использовать аккаунт». Вместо этого речь шла о «ты». Большое спасибо.

1 Ответ

0 голосов
/ 02 января 2019
...