简体   繁体   中英

c++ sql connection “get_driver_instance(); is undefined ” error

MyCode is ;

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

When I run the code,I take the message "reference undefined get_driver_instance();" What should I do

I solved the problem. The reason is that I am working on Ubuntu, I should have run it from terminal, with the code ; g++ -o sado 1667138.cpp -lmysqlcppconn sadu is the name of execute file, and -lmysqlcppconn is adding the mysql library to cpp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM