mysql-connector-c - ‘get_driver_instance’ не является членом ‘sql:: mysql’

Я - новичок в C++ и изобразил единственный способ, которым я собираюсь учиться, должен испачкаться с некоторым кодом. Я пытаюсь создать программу, которая соединяется с mysql базой данных. Я использую g ++ на Linux. Без язя.

Я работаю, "делают", и это - моя ошибка:

hello.cpp:38: error: ‘get_driver_instance’ is not a member of ‘sql::mysql’
make: *** [hello.o] Error 1

Вот мой код включая make-файл. Любая Справка была бы большой!Заранее спасибо

###BEGIN hello.cpp###

#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>

#include "mysql_connection.h"

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

#define EXAMPLE_HOST "localhost"
#define EXAMPLE_USER "root"
#define EXAMPLE_PASS ""
#define EXAMPLE_DB "world"

using namespace std;
using namespace sql::mysql;

int main(int argc, const char **argv)
{   

    string url(argc >= 2 ? argv[1] : EXAMPLE_HOST);
    const string user(argc >= 3 ? argv[2] : EXAMPLE_USER);
    const string pass(argc >= 4 ? argv[3] : EXAMPLE_PASS);
    const string database(argc >= 5 ? argv[4] : EXAMPLE_DB);

    cout << "Connector/C++ tutorial framework..." << endl;
    cout << endl;


    try { 
        sql::Driver *driver;
        sql::Connection *con;
        sql::Statement  *stmt;
        driver = sql::mysql::get_driver_instance();
        con = driver->connect("tcp://127.0.0.1:3306", "user", "password");
        stmt = con->createStatement();
        stmt->execute("USE " EXAMPLE_DB);
        stmt->execute("DROP TABLE IF EXISTS test");
        stmt->execute("CREATE TABLE test(id INT, label CHAR(1))");
        stmt->execute("INSERT INTO test(id, label) VALUES (1, 'a')");
        delete stmt;
        delete con;

    } catch (sql::SQLException &e) {
        /*
          The MySQL Connector/C++ throws three different exceptions:

          - sql::MethodNotImplementedException (derived from sql::SQLException)
          - sql::InvalidArgumentException (derived from sql::SQLException)
          - sql::SQLException (derived from std::runtime_error)
        */
        cout << "# ERR: SQLException in " << __FILE__;
        cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
        /* Use what() (derived from std::runtime_error) to fetch the error message */
        cout << "# ERR: " << e.what();
        cout << " (MySQL error code: " << e.getErrorCode();
        cout << ", SQLState: " << e.getSQLState() << " )" << endl;

        return EXIT_FAILURE;
    }

    cout << "Done." << endl;
    return EXIT_SUCCESS;
}
###END hello.cpp###

###BEGIN Make File###
SRCS     := hello.cpp
OBJS     := $(SRCS:.cpp=.o)
CXXFLAGS := -Wall -pedantic
INCPATHS := -I/home/user/mysql-connector/include/
LIBPATHS := -L/home/user/mysql-connector/lib/ -L/home/user/mysql-connector-c/lib/
LIBS     := -static -lmysqlclient -mysqlcppconn-static
EXE      := MyExecutable



$(EXE): $(OBJS)
    $(CXX) $(OBJS) $(LIBPATHS) $(LIBS) -o $@

.cpp.o:
    $(CXX) $(CXXFLAGS) $(INCPATHS) -c $< -o $@

###End Makefile###
8
задан Thomas Matthews 12 June 2010 в 06:14
поделиться

2 ответа

Включить: ??

#include "mysql_driver.h" 
1
ответ дан 5 December 2019 в 23:13
поделиться

Похоже, эта функция находится в глобальном пространстве имен, не добавляйте перед sql :: mysql ::

0
ответ дан 5 December 2019 в 23:13
поделиться
Другие вопросы по тегам:

Похожие вопросы: