gpt4 book ai didi

c++ - mysql C++ 中的连接崩溃

转载 作者:行者123 更新时间:2023-11-29 00:28:10 27 4
gpt4 key购买 nike

目前,我已经实现了一个写入 mysql 数据库的程序...我也在使用带有 C++ 的 Xcode。我已经正确地导入了所有的库,但是我在这一行收到了 BAD EXCESS 错误消息:

    con = driver->connect("tcp://127.0.0.1:3306", "root", "root");

似乎是什么问题?这是完整的程序...

#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)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl;
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", "root");
// Connect to the MySQL test database
con->setSchema("test");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");

while (res->next()) {
cout << "\t... MySQL replies: ";
// Access column data by alias or column name
cout << res->getString("_message") << endl;
cout << "\t... MySQL says it again: ";
// Access column fata by numeric offset, 1 is the first column
cout << res->getString(1) << endl;
}

delete res;
delete stmt;
delete con;

} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}

编辑 目前,我查看了这个 topic这与我的几乎完全相似,但我仍然很迷茫......我将如何使用 cmake 重新编译 mysql 并更改这些标志?

我已经处理这个问题好几个小时了,但没有真正完成任何编码......只是用一张脸盯着我的屏幕>:(。

最佳答案

这里有一个类似的问题(几乎一模一样?),你检查了吗?

关于c++ - mysql C++ 中的连接崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17980387/

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