首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:连接处于autoCommit模式

错误:连接处于autoCommit模式
EN

Stack Overflow用户
提问于 2015-01-19 01:26:05
回答 2查看 1.1K关注 0票数 1

我的代码出了什么问题?我正在使用mysql连接器来处理mysql数据库。在构建阶段,一切看起来都很酷,但当我运行代码时,我得到了这个错误:

代码语言:javascript
复制
ERROR: SQLException in /programs/Mysql/main.cpp (main) on line 24
ERROR: The connection is in autoCommit mode (MySQL error code: 0, SQLState: )

这是我的完整代码:

代码语言:javascript
复制
#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;
}

有什么想法吗?

EN

回答 2

Stack Overflow用户

发布于 2015-08-20 04:21:54

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

在将includes指向正确的MySQL发行版标题之后,我再也没有收到这个错误。

票数 1
EN

Stack Overflow用户

发布于 2015-01-19 01:28:14

“连接处于autoCommit模式”,因此您无法启动事务。

因此,找到将autoCommit设置为false的方法。

autoCommit模式是mySql的默认模式,这意味着每个语句都是它自己的事务。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28012620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档