将Raspberry Pi 2与外部远程数据库连接
Connecting the Raspberry Pi 2 with an External Remote Database
我想在C++的帮助下将我的Raspberry Pi 2连接到000webhost.com上的外部MySQL数据库。
#include <stdlib.h>
#include <iostream>
#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)
{
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("<000webhost mysql address>", "<username>", "<password>");
/* Connect to the MySQL test database */
con->setSchema("<database>");
stmt = con->createStatement();
res = stmt->executeQuery("<sql statement>"); // replace with your statement
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 fata 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;
}
我收到一个错误,说mysql_connection.h
文件不见了。我不知道我做错了什么,也不知道有没有更简单的方法。请帮我处理这件事。谢谢
我收到一个错误,说mysql_connection.h文件丢失了。
根据您描述的错误消息和对我的问题"您安装了mysql_connection.h
的源代码吗?"的回答,即:
I没有在树莓pi上安装mysql,因为我试图访问外部数据库。
(这不是我问的。)似乎#include "mysql_connection.h
不起作用的原因是因为库不在那里。
根据文档,Connector/C
库不需要安装MySQL,但必须安装Connector/C
源以包含库中的头。
MySQL的Connector/C
库需要提升;然而,Raspian已经安装了boost,尽管这可能会带来它自己的一系列问题,如果你在boost方面遇到问题,这里会讨论并解决这些问题。(如果你的树莓派有NOOBS,我建议切换到Raspian。)
虽然链接在我的评论中,但MySQL的文档中提供了安装Connector/C
库的说明。
我收集了一些资源和链接,这些资源和链接应该会提供一些额外的帮助:
- 如何安装第三方库
- 如何#包括第三方库
- 在Unix和类Unix系统上从源代码安装连接器/C++
相关文章:
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- 如何在多个线程中创建 QSql数据库连接时防止名称冲突
- 数据库连接并将数据从C ++程序保存到MySQL
- 在 C++ 中获取数据库连接
- Firebase C++ Windows 上的实时数据库连接丢失
- 我不能使用 mysql 数据库连接同时使用插入和选择.C++
- C++ Qt SQL lite 数据库连接问题
- C++ 程序中的数据库连接检查
- 打开与 Qt/C++ 的数据库连接
- 如何修复数据库连接的C 程序运行时间错误(0xc0000005)
- 使用libpq组织PostgreSQL数据库连接参数
- Qt 中的数据库连接池
- Qt-同时处理多个数据库连接
- 使用QT C 为Sevaral表单创建常见的数据库连接
- 将Raspberry Pi 2与外部远程数据库连接
- 是否允许在同一 Sqlite 数据库连接中启动多个事务
- IIS-部署ASP.NET网站和数据库连接
- 没有数据库连接的字符串转义
- Singletone中的数据库连接
- 正在将数据库连接到本地网络中的程序