【发布时间】:2015-01-18 17:26:05
【问题描述】:
我的代码有什么问题?我正在使用 mysql 连接器来处理 mysql 数据库。在构建阶段一切看起来都很酷,但是当我运行我的代码时,我得到了这个错误:
ERROR: SQLException in /programs/Mysql/main.cpp (main) on line 24
ERROR: The connection is in autoCommit mode (MySQL error code: 0, SQLState: )
这是我的完整代码:
#include <stdlib.h>
#include <iostream>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/prepared_statement.h>
using namespace std;
using namespace sql;
int main(void) {
try {
Driver *driver;
Connection *con;
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "123");
con->setAutoCommit(0);
con->setSchema("webscope");
delete con;
} catch (SQLException &e) {
cout << "ERROR: SQLException in " << __FILE__;
cout << " (" << __func__ << ") on line " << __LINE__ << endl;
cout << "ERROR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << ")" << endl;
if (e.getErrorCode() == 1047) {
/*
Error: 1047 SQLSTATE: 08S01 (ER_UNKNOWN_COM_ERROR)
Message: Unknown command
*/
cout << "\nYour server does not seem to support Prepared Statements at all. ";
cout << "Perhaps MYSQL < 4.1?" << endl;
}
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
有什么想法吗?
【问题讨论】:
-
我删除了一些 cmets 以获得更短的代码 sn-p。
-
很抱歉碰到了这个问题,你解决过这个问题吗?我也有同样的问题。
标签: c++ mysql mysql-connector