我简单的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;
}发布于 2014-03-05 03:28:12
在深入研究了头文件的语句之后,我发现有一个名为executeUpdate的函数(下面的函数头)
virtual int executeUpdate(const sql::SQLString& sql) = 0;这最终做了我想做的事。程序将值添加到数据库中,而不引发任何异常。
我希望mySQL C++连接器库没有这么糟糕的文档。
https://stackoverflow.com/questions/22187118
复制相似问题