2011-11-02 32 views
0

我正在与MySQL CPP连接器的C++程序,而且我坚持到:MySQL的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方法都实现了,但我不明白为什么这个函数不是,如果它是基本的。

谢谢你在前进, 维克托

+0

我测试了它在另一台计算机和它的作品...可能是库搞砸。将在干净的Linux安装后尝试。 – olivarra1

回答

1

今天下午我有同样的问题。现在我已经找到了一种方法来解决它,希望我的经验对你有所帮助: 我使用的是Ubuntu 10.10并通过突触包管理器安装mysql连接器/ C++。我找到了动态lib文件(libmycppconn.so.xxxx) - 它的大小是几十千字节。无意中,我得到一个已经编译好的lib文件,其编号为http://dev.mysql.com/downloads/connector/cpp/1.0.html,它的大小是9兆字节或更少,这意味着它可能包含更多的前一个。所以我决定删除突触,编译源代码,并进行安装。完成这些之后,图书馆找到了工作。 也许你可以尝试编译源代码并安装它。

好运, 曦