gpt4 book ai didi

c++ - 错误: The connection is in autoCommit mode

转载 作者:行者123 更新时间:2023-11-29 20:58:53 24 4
gpt4 key购买 nike

我的代码有什么问题吗?我正在使用 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;
}

有什么想法吗?

最佳答案

我实际上遇到了这个问题,因为我的项目的 Makefile 中包含了错误的头文件。

在我的 Makefile 中,我包含了 Solaris 版本的 MySQL 的 header ,但在 Linux 上进行编译。在将包含内容指向正确的 MySQL 发行 header 后,我不再收到此错误。

关于c++ - 错误: The connection is in autoCommit mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37396598/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com