![](/img/trans.png)
[英]Is C++ OTL SQL database library using parameterized queries under the hood, or string concat?
[英]Insert data into mysql table from c++ program using OTL library
我想將int
和string
值從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
。
我在這里看到了示例: OTL mysql示例 。 對我有用嗎?
以及如何在系統中設置OTL環境? 我需要安裝它還是什么?
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.