C++ SQL 连接"get_driver_instance(); is undefined "错误

c++ sql connection "get_driver_instance(); is undefined " error

本文关键字:错误 is undefined driver SQL 连接 get C++ instance      更新时间:2023-10-16

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

运行代码时,我会输入消息"参考undefined get_driver_instance();"我该怎么办

我解决了问题。原因是我在Ubuntu上工作,我应该用代码从终端运行它。g -o sado 1667138.cpp -lmysqlcppconn sadu是execute文件的名称,-lmysqlcppconn正在将mysql库添加到cpp

相关文章: