我想面向错误代码,而我想插入sql数据库
错误: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;
}
答案 0 :(得分:1)
在MySQL中使用反引号来转义列和表名以及引号以转义字符串
INSERT INTO `Conveyor-BELT` (`BARCODE`, `TIM121`)
VALUES('5555', '5555')