gpt4 book ai didi

c++ - MySQL C++ 未实现异常

转载 作者:行者123 更新时间:2023-11-28 08:14:53 25 4
gpt4 key购买 nike

我正在用 MySQL cpp 连接器制作一个 c++ 程序,我陷入了:

sql::MethodNotImplementedException on 
MySQL_Connection::prepareStatement(const sql::SQLString& sql, int autoGeneratedKeys)

我搜索了很多但什么也没找到...我真的不明白发生了什么。这是失败类的完整源代码:

#ifndef __DATABASE_H_
#define __DATABASE_H_

#include <string>
#include <mysql_connection.h>
#include <mysql_driver.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

#define MYSQL_HOSTNAME "localhost"
#define MYSQL_USERNAME "dummy"
#define MYSQL_PASSWORD "password"

using namespace std;
using namespace sql;

class Database {
public:
Database();

static bool login(const string &user, const string &password);

static Connection *createConnection();
};

#endif

来源:

Connection *Database::createConnection(){
mysql::MySQL_Driver *driver = mysql::MySQL_Driver::Instance();

return driver->connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
}

bool Database::login(const string &user, const string &password){
bool ret;
Connection *con = createConnection();
PreparedStatement *pstmt = con->prepareStatement("SELECT * FROM Players WHERE Username = ? AND Password = ?"); // here's where it fails ._.

pstmt->setString(1, user);
pstmt->setString(2, password);

ResultSet *res = pstmt->executeQuery();
ret = res->next();

res->close();
delete(res);
pstmt->close();
delete(pstmt);
con->close();
delete(con);

return ret;
}

当我编译和链接它时,我将 -lmysqlcppconn 添加为库。

我查看了 MySQL c++ 引用资料,他们说并非所有 JDBC 方法都已实现,但我不明白为什么该函数没有实现,如果它是一个基本函数的话。

先谢谢你,维克多

最佳答案

我今天下午遇到了同样的问题。现在我找到了解决方法,希望我的经验对你有帮助:我正在使用 ubuntu 10.10 并通过突触包管理器安装 mysql connector/c++。我找到了动态 lib 文件 (libmycppconn.so.xxxx)——它的大小是几十千字节。一不小心,我在 http://dev.mysql.com/downloads/connector/cpp/1.0.html 得到了一个已经编译好的 lib 文件。 ,它的大小大约为 9 兆字节,这意味着它可能包含比前一个更多的内容。所以我决定删除 synaptic 那个,然后编译源代码,然后 make/make install 它。完成此操作后,库会找到。也许你可以尝试编译源代码并安装它。

祝你好运,习

关于c++ - MySQL C++ 未实现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7988089/

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