c++ - 使用 mysql 连接器构建程序时出错

标签 c++ mysql

我有以下编译时错误我找不到原因: fatal error :mysql_connection.h:没有那个文件或目录

/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>

/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
int main(void)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' »AS _message'..." << endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
cout << res->getString("_message") << endl;
cout << "\t... MySQL says it again: ";
/* Access column data by numeric offset, 1 is the first column */
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete con;
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " »
<< __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}

我在 Codeblocks 中编译它并且我已经安装了 mysql 连接器 我是第一次尝试,请帮忙!

最佳答案

您很可能缺少 libmysqlcppconn-dev。安装后,错误应该消失。

关于c++ - 使用 mysql 连接器构建程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40196728/

相关文章:

java - AsyncTask 不返回任何响应

php - php 中出现 MySQL 错误,但 phpmyadmin 中没有错误

c# - 根据Mysql表中的同一月份计算Date列

c++ - unique_ptr & vector,试图访问已删除的函数,Visual Studio 2013

c++ - #define - 预期和表达式 C++

c++ - 如何正确迭代QT的STL风格 vector

mysql - 有没有更简单的方法来编写这个查询?

c++ - 如何在 C++ 中使用 ZeroMQ 发送包含数组的结构时解决错误

c++ - 文件映射和文件结构

mysql - 使用连接重述子查询