、安装好boost。
、从官网下载mysql connector c++版本。
、解压,复制 include/jdbc/cppconn 文件夹复制,到/usr/local/include/cppconn目录。,其他.h文件到到/usr/local/include/。 4、复制lib64中库文件到/usr/local/lib/目录中。
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#include <stdio.h>
using namespace std; int main(void)
{
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;
try {
driver = get_driver_instance();
con = driver->connect("tcp://127.00.1:3306", "root", "command");
con->setSchema("viewfocus");
}
catch (sql::SQLException &e)
{
printf("error \n");
}
return ;
}
SRC += main.cpp
GCC = g++
FLAG = -lmysqlcppconn
CMS = CMS demo:
$(GCC) -o $(CMS) -g $(SRC) $(FLAG)
clean:
rm CMS
CMysqlConnectPtr mysqlMgr::CreateConnection()
{
db_conf db = config::get_db_conf(); bool b_true = true;
char strHonst[] = { '\0' };
int nTime_out = ;
snprintf(strHonst, sizeof(strHonst), "tcp://%s:%s", db.strDBIP.c_str(), db.strDBPort.c_str());
spd::get("console")->info("{}", strHonst);
sql::Connection *conn = driver->connect(strHonst, db.strDBUser.c_str(), db.strDBPswd.c_str());
conn->setClientOption("OPT_CONNECT_TIMEOUT", &nTime_out);
conn->setClientOption("OPT_RECONNECT", &b_true);
conn->setClientOption("CLIENT_MULTI_RESULTS", &b_true);
conn->setClientOption("OPT_CHARSET_NAME", "utf8");
conn->setSchema(db.strDBName.c_str());
std::shared_ptr<sql::Connection> sp(conn,[](sql::Connection *conn) {
delete conn;
}); return sp;
}
    //*************************************************************************
// 函数名称: SyncExecSQL
// 返 回 值: bool --执行成功返回true, 否则返回false
// 参 数: FUNCCALL fun --可以是回调函数,仿函数,lambda表达式
// 函数说明: 同步执行一个数据库操作,
//*************************************************************************
template<class FUNCCALL>
bool SyncExecSQL(FUNCCALL fun)
{
bool bResult = false; CMysqlConnectPtr pDB = CreateConnection();
if (!pDB)
{
spd::get("console")->info("{} {} {}", __FILE__, __LINE__,"SyncExecSQL(FUNCCALL fun)");
return bResult;
}
try
{
fun(pDB);
bResult = true;
}
catch (sql::SQLException &e)
{
spd::get("console")->info("{} {} {}", __FILE__, __LINE__, "sql::SQLException");
}
catch (...)
{
}
return true;
}
void mysqlMgr::loadMonitor()
{
cleanMap(); string strSql = "SELECT Dev_Code, Video_Alarm_Type from m_monitor "; SyncExecSQL([&](CMysqlConnectPtr pDB)
{
try {
std::unique_ptr<sql::PreparedStatement> pstmt(pDB->prepareStatement(strSql));
std::unique_ptr<sql::ResultSet> res(pstmt->executeQuery());
if (res)
{
while (res->next())
{
int index = MYSQL_BASE_INDEX_1; string devCode = res->getString(++index);
string alamType = res->getString(++index); add2Map(devCode, alamType);
}
}
}
catch (sql::SQLException &e)
{
return false;
}
return true;
});
}

Linux::mysql-connector-c++的更多相关文章

  1. [转]MySQL Connector/C++(一)

    http://www.cnblogs.com/dvwei/archive/2013/04/18/3029464.html#undefined#undefined MySQL Connector/C++ ...

  2. MySQL Connector/C++ C++连接mysql

    MySQL :: MySQL Connector/C++ Developer Guide :: 1 Introduction to Connector/C++ https://dev.mysql.co ...

  3. MySQL、Hive以及MySQL Connector/J安装过程

    MySQL安装 ①官网下载mysql-server(yum安装) wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch. ...

  4. 创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL

    创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL 用惯.NET的研发人员都习惯性地使用SQLServer作为数据库.然而.NET Core ...

  5. vc++2013中使用MySQL connector/C++ 1.1.4静态链接报错

    包含头文件 #include <mysql_connection.h> #include <mysql_driver.h> #include <cppconn/state ...

  6. Using MySQL Connector .NET 6.6.4 with Entity Framework 5

    I had been waiting for the latest MySQL connector for .NET to come out so I can move on to the new a ...

  7. linux mysql远程连接

    今天在本地连接linux服务端的mysql始终报错61,谷歌后找到原因: linux的mysql默认是不允许远程连接操作的,在stack上面找到方法:修改mysql配置文件/usr/local/mys ...

  8. mysql.connector操作mysql的blob值

    This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and re ...

  9. ubuntu linux mysql 安装 基本操作 命令

    mysql --help #如果有信息证明系统已经安装了mysql mysql -V #查看版本号 netstat -tap|grep mysql #检查mysql是否在启动状态 卸载mysql: s ...

  10. Ubuntu & MacOS安装Mysql & connector

    Ubuntu & MacOS安装Mysql & connector 1. 安装MySql sudo apt-get install mysql-server apt-get insta ...

随机推荐

  1. Tomcat类加载器体系结构

    <深入理解java虚拟机>——Tomcat类加载器体系结构 标签: java / 虚拟机 / tomcat Tomcat 等主流Web服务器为了实现下面的基本功能,都实现了不止一个自定义的 ...

  2. .Net Standard(.Net Core)实现获取配置信息

    一.前言 在.Net Framework框架有专门获取webconfig配置的方法供我们使用,但是在.Net Core或者.Net Standard中没有可以直接使用的方法来获取配置文件信息,下面就来 ...

  3. 深入解析 Kubebuilder:让编写 CRD 变得更简单

    作者 | 刘洋(炎寻) 阿里云高级开发工程师 导读:自定义资源 CRD(Custom Resource Definition)可以扩展 Kubernetes API,掌握 CRD 是成为 Kubern ...

  4. WordPress后台地址路径修改方法

    用过WordPress后台的,其实都知道http://域名目录/wp-login.php就是登录地址,如果这时候使用暴力破解,很可能破解密码(这就有些想象力了),下面芝麻带你看看如何自定义美观的地址. ...

  5. jenkins自动化部署项目3 --设置用户

    我直接设置的admin ,jenkins可以新建多个用户,并赋予不同的权限(TODO) 等后续需要严格规范操作人的时候再补充

  6. Elastic Static初识(01)

    写在前面 Elastic Static 是指由Elasticsearch,Logstash,Kibana,Beats等组件结合起来而构成的一个数据收集,分析,可视化的一个架构.我们经常听说过的ELK就 ...

  7. 编程范式 --- 面向协议编程(Protocol Oriented Programming,简称POP)

    面向协议编程(Protocol Oriented Programming,简称POP) 是Swift的一种编程范式,Apple于2015年WWDC踢出 在Swift的标准库中,能见到大量POP的影子 ...

  8. 浅析java垃圾回收机制

    什么是java程序中的垃圾?什么这些垃圾又是怎样被回收的?为什么会被回收?不进行回收又会怎样?这些问题都是我们要在这篇博客中要解决的问题! 大家都知道,在c语言中,作为程序员,必须得考虑到去怎样回收已 ...

  9. 如何评价一个VR体验设计?

    如何评价一个VR系统的体验是好是坏?或者说,哪些因素会破坏一个VR的体验? Kruij和Riecke教授在IEEE VR会议上提到了四个角度:Congnition,Game User Experien ...

  10. 13.Django基础之django分页

    一.Django的内置分页器(paginator) view from django.shortcuts import render,HttpResponse # Create your views ...