c++ - 使用 OTL 库从 C++ 程序将数据插入 mysql 表

标签 c++ mysql sql otl

我要插入intstring从 C++ 程序到 mysql 表的值。

for (std::map < int, std::vector < std::string > >::iterator hit = three_highest.begin(); hit != three_highest.end(); ++hit) {
    //std::cout << hit->first << ":";

    for (std::vector < std::string >::iterator vit = (*hit).second.begin(); vit != (*hit).second.end(); vit++) {
        std::cout << hit->first << ":";
        std::cout << *vit << "\n";

我要插入 hit->first*vit .

  1. 我在这里看到了例子:OTL Example for mysql .它对我有用吗?

    如何在我的系统中设置OTL环境?我需要安装它还是什么?

  2. 这是另一种方式的非常简单的示例。但是它直接include <mysql.h>我在我的系统中找不到。使用什么环境?

我使用的是 Linux - Ubuntu 环境。

最佳答案

在这里,我得到了如何将 c++ 与 mysql 连接:

首先从源代码编译了 c++ 连接器库,但过了一会儿我想我可能做错了什么所以我只是使用 apt 来获取它:

sudo apt-get install  libmysqlcppconn-dev

所以我现在已经遇到这个问题一个星期了,我也对它感到非常沮丧。我刚刚终于能够构建一个除了登录 mysql 之外什么都不做的程序,我真的高兴得尖叫起来。这是我的资料,希望对您有所帮助。

我首先从源代码编译了 c++ 连接器库,但过了一会儿我想我可能做错了什么所以我只是使用 apt 来获取它:

sudo apt-get install libmysqlcppconn-dev

这是我的简单测试源文件“tester.cpp”

#include <stdlib.h>
#include <iostream>
#include <mysql_connection.h>
#include <driver.h>
#include <exception.h>
#include <resultset.h>
#include <statement.h>

using namespace sql;
int main(void){
  sql::Driver *driver;
  sql::Connection *con;

  driver = get_driver_instance();
  con = driver->connect("tcp://127.0.0.1:3306","root","YOURPASSWORD");

  return 0;
}

最后是 g++ 编译命令:

sudo g++ -Wall -I/usr/include/cppconn -o testapp tester.cpp -L/usr/lib -lmysqlcppconn

关于c++ - 使用 OTL 库从 C++ 程序将数据插入 mysql 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18605751/

相关文章:

c++ - RPC、套接字和性能注意事项

MySQL 请求 COUNT 问题

sql - MS SQL Server 2005 GROUP BY 和 SUM

mysql - SQL递归添加日期直到数据集每天有一条记录

php - 仅显示前 5 个结果

SQL - 查找行之间的值

c++来自无拷贝的密集 vector 的特征 block 对角矩阵

android - Qt Quick Controls 2 启动画面

c++ - 计算 GL_TRIANGLE 的顶点法线

mysql - hibernate.ddl.auto=更新创建DDL错误CommandAcceptanceException