windows 10上mysql的c++代码块链接器问题

r8xiu3jd  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(257)

我正在尝试连接到我的远程数据库mysql服务器。我在Windows10EnterpriseMysql连接器c1.1.9的代码块17.12IDE中使用c
以下是我的构建选项。

我使用以下代码测试连接:


# include <iostream>

# include <cstdlib>

# include <string>

using namespace std;

# include "cppconn/driver.h"

# include "cppconn/exception.h"

# include "cppconn/resultset.h"

# include "cppconn/statement.h"

# pragma comment(lib, "mysqlcppconn.lib")

const string server   = "tcp://127.0.0.1:3310";
const string username = "user";
const string password = "password"; 
int main()
{
    sql::Driver     *driver; 
    sql::Connection *dbConn;  
    object
    sql::Statement  *stmt;   
    sql::ResultSet  *res;    
    try
    {
        driver = get_driver_instance();
    }
    catch (sql::SQLException e)
    {
        cout << "Could not get a database driver. Error message: " << 
        e.what() << endl;
        system("pause");
        exit(1);
   }
   // Try to connect to the DBMS server
   try
   {
       dbConn = driver->connect(server, username, password);
   }
   catch (sql::SQLException e)
   {
       cout << "Could not connect to database. Error message: " << e.what() 
       << endl;
       system("pause");
       exit(1);
   }
   stmt = dbConn->createStatement();
   try
   {
       stmt->execute("USE teste");            
       res = stmt->executeQuery("show tables"); 
   }
   catch (sql::SQLException e)
   {
       cout << "SQL error. Error message: " << e.what() << endl;
       system("pause");
       exit(1);
   }
   while (res->next())
   {
      cout << res->getString(1) << endl;
   }
  delete res;
  delete stmt;
  delete dbConn;  
  system("pause");
  return 0;
}

我得到以下错误。

如何修复?
更新

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题