c ++ sql connection“get_driver_instance();未定义”错误

时间:2014-03-08 12:26:06

标签: c++

MyCode是;

 #include<iostream>

using namespace std;

 #include <string>

 #include "mysql_connection.h"

 #include <stdlib.h>

 #include <iomanip>

 #include <cppconn/driver.h>

 #include <cppconn/exception.h>

 #include <cppconn/resultset.h>

 #include <cppconn/statement.h>

 #include <cppconn/prepared_statement.h>


int main(){


cout<<"sadullah";


    string database = "sch1667138";
        string ipAdress = "144.122.71.165";
        string password = "???";
        string userName = "???";

        sql::Driver *driver;
        sql::Connection *con;

    try {
        driver =get_driver_instance();

        con = driver->connect("tcp://" + ipAdress + ":3306", userName,
                password);

        con->setSchema("sch1667138");

        cout << "successfully connected to db...." << endl;

    } catch (sql::SQLException &e) {
        cout << e.what() <<endl;
    }


return 0;
}

当我运行代码时,我会收到消息“reference undefined get_driver_instance();”我该怎么办

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。原因是我正在研究Ubuntu,我应该从终端运行它,带代码; g ++ -o sado 1667138.cpp -lmysqlcppconn sadu是执行文件的名称,-lmysqlcppconn正在将mysql库添加到cpp