INSERT INTO SQL 出现 C++ 错误 1064 42000
INSERT INTO SQL With c++ error 1064 42000
我想插入 sql 数据库时遇到错误代码
error :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;
}
在 MySQL 中使用反引号转义列并使用 table 名称和引号转义字符串
INSERT INTO `Conveyor-BELT` (`BARCODE`, `TIM121`)
VALUES('5555', '5555')
我想插入 sql 数据库时遇到错误代码
error :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;
}
在 MySQL 中使用反引号转义列并使用 table 名称和引号转义字符串
INSERT INTO `Conveyor-BELT` (`BARCODE`, `TIM121`)
VALUES('5555', '5555')