0

I'm making a c++ program with MySQL cpp connector, and i'm stuck into:

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

I searched a lot but couldn't find nothing... i really don't understand what's happening. Here's the full source of the class that fails:

#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

And the sources:

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;
}

When i compile and link it, i add -lmysqlcppconn as library.

I checked MySQL c++ reference and they say that not all JDBC methods are implemented, but i can't understand why that function is not, if it's a basic one.

Thank you in advance, Víctor

1
  • I tested it in another computer and it works... might be libraries messed up. will try after a clean linux install.
    – olivarra1
    Nov 3, 2011 at 18:52

1 Answer 1

1

I had the same problem this afternoon. And now I have found a way to solve it, hope my experience is helpful to you: I am using ubuntu 10.10 and install mysql connector/c++ by synaptic package manager. And I found the dynamic lib file (libmycppconn.so.xxxx) -- it's size is decades of kilobytes. By accidentally, I get an already compiled lib file at http://dev.mysql.com/downloads/connector/cpp/1.0.html, it's size is 9 megabytes more or less, which means it may contain a lot more then the previous one. So I decided to remove the synaptic one, and compile the source code, and make / make install it. After I have done this, the libraries work find. Maybe you can try to compile the source code and install it.

Good Luck, Xi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.