繁体   English   中英

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

[英]Insert data into mysql table from c++ program using OTL library

我想将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 mysql示例 对我有用吗?

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

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

我正在使用Linux-Ubuntu环境。

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

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

sudo apt-get install  libmysqlcppconn-dev

所以我现在已经有一个星期的问题了,对此我也感到非常沮丧。 我现在终于能够构建一个程序,除了登录mysql以外什么都不做,而我确实高兴极了。 这是我所拥有的,希望对您有所帮助。

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

须藤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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM