其他分享
首页 > 其他分享> > c-错误:连接处于autoCommit模式

c-错误:连接处于autoCommit模式

作者:互联网

我的代码有什么问题?我正在使用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的标头,但在Linux上进行了编译.在将包含指向正确的MySQL发行标头之后,我再也没有收到此错误.

标签:mysql-connector,c,mysql
来源: https://codeday.me/bug/20191013/1910703.html