我的简单mysql c ++连接器程序抛出错误15.这是什么意思?代码直接来自在线文档。我找不到任何地方记录的错误代码。这很奇怪,因为数据最终会插入到表中。是的我知道我的语句应该参数化以避免SQL注入,这只是一个简单的测试程序。
#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 "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
int main(void)
{
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "1092Wilda");
/* Connect to the MySQL test database */
con->setSchema("test");
stmt = con->createStatement();
res = stmt->executeQuery("INSERT INTO bung VALUES ('39', 'TestVal')");
delete res;
delete stmt;
delete con;
} catch (sql::SQLException &e) {
cout << e.getErrorCode();
}
cout << endl;
return EXIT_SUCCESS;
}
答案 0 :(得分:0)
在头文件statement.h中挖掘后,我发现有一个名为executeUpdate的函数(下面的函数头)
virtual int executeUpdate(const sql::SQLString& sql) = 0;
这最终做了我想做的事。程序将值添加到数据库中而不会抛出任何异常。
我希望mySQL C ++连接器库没有那么糟糕的文档。