2016-02-28 146 views
-1

我對着錯誤代碼,而我想插入SQL數據庫INSERT INTO SQL用C++錯誤1064 42000

錯誤:1064 SQLSTATE:42000

這裏是我的代碼:

string* DB(string barcode) 
{ 
    try { 
     sql::Driver *driver; 
     sql::Connection *con; 
     sql::Statement *stmt; 
     sql::ResultSet *res; 
     /* Create a connection */ 
     driver = get_driver_instance(); 
     con = driver->connect("sql14.main-hosting.eu", "u103222348_user", "newsystem"); 
     /* Connect to the MySQL test database */ 
     con->setSchema("u103222348_read"); 

     stmt = con->createStatement(); 

     res = stmt->executeQuery("INSERT INTO 'Conveyor-BELT' ('BARCODE', 'TIM121') VALUES('5555','5555')"); 
     while (res->next()) { 

      /* Access column data by alias or column name */ 


     } 
     delete res; 
     delete stmt; 
     delete con; 

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

    return EXIT_SUCCESS; 
} 

回答

1

在MySQL中使用反引號逃脫列和表名並引用逃避串

INSERT INTO `Conveyor-BELT` (`BARCODE`, `TIM121`) 
VALUES('5555', '5555')