Linux::mysql-connector-c++
、安装好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++的更多相关文章
- [转]MySQL Connector/C++(一)
http://www.cnblogs.com/dvwei/archive/2013/04/18/3029464.html#undefined#undefined MySQL Connector/C++ ...
- MySQL Connector/C++ C++连接mysql
MySQL :: MySQL Connector/C++ Developer Guide :: 1 Introduction to Connector/C++ https://dev.mysql.co ...
- MySQL、Hive以及MySQL Connector/J安装过程
MySQL安装 ①官网下载mysql-server(yum安装) wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch. ...
- 创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL
创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL 用惯.NET的研发人员都习惯性地使用SQLServer作为数据库.然而.NET Core ...
- vc++2013中使用MySQL connector/C++ 1.1.4静态链接报错
包含头文件 #include <mysql_connection.h> #include <mysql_driver.h> #include <cppconn/state ...
- 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 ...
- linux mysql远程连接
今天在本地连接linux服务端的mysql始终报错61,谷歌后找到原因: linux的mysql默认是不允许远程连接操作的,在stack上面找到方法:修改mysql配置文件/usr/local/mys ...
- mysql.connector操作mysql的blob值
This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and re ...
- ubuntu linux mysql 安装 基本操作 命令
mysql --help #如果有信息证明系统已经安装了mysql mysql -V #查看版本号 netstat -tap|grep mysql #检查mysql是否在启动状态 卸载mysql: s ...
- Ubuntu & MacOS安装Mysql & connector
Ubuntu & MacOS安装Mysql & connector 1. 安装MySql sudo apt-get install mysql-server apt-get insta ...
随机推荐
- CTF常用软件/工具
慢慢更新 整合版: http://www.jz5u.com/Soft/Progra/tool/163275.html/ 各种在线工具以及工具整合 http://www.ctftools.com/ 逆向 ...
- 具有注册、登陆以及后台管理功能的web开发
设计一个带有注册.登陆.后台用户管理的网站 使用(Html+Css+JavaScript+Jsp+Servlet+JDBC+JSTL+EL) 工具:Eclipse(NetBeans).Mysql8.0 ...
- 2019年研究生数学建模D题《汽车行驶工况构建》解析
正在整理...
- Java String 对象,你真的了解了吗?
String 对象的实现 String对象是 Java 中使用最频繁的对象之一,所以 Java 公司也在不断的对String对象的实现进行优化,以便提升String对象的性能,看下面这张图,一起了解一 ...
- linux虚拟化简介
为跨平台而生 在计算机发展的早期,各类计算平台.计算设备所提供的接口.调用方式纷繁复杂,没有像今天这样相对统一的标准.由于需要适配不同的平台,需要写很多繁琐的兼容代码,这无形中给开发者带来了很大的不便 ...
- 用Python构造ARP请求、扫描、欺骗
目录 0. ARP介绍 1. Scapy简述 2. Scapy简单演示 2.1 安装 2.2 构造包演示 2.2.1 进入kamene交互界面 2.2.2 查看以太网头部 2.2.3 查看 ICMP ...
- js实现敲回车键登录
任何一个网站页面都有登陆界面,很多时候在输入好用户名和密码后,还要用鼠标去点一个类似于登陆什么的按钮或者链接.这样你才能进网站做你喜欢做的事情. 有时候我就在想是不是能在输入好我该输入的东西后,直接敲 ...
- Angular 开发NPM第三方包
步骤: 创建第三方包 > 开发第三方包 > 测试第三方包 > 发布第三方包 > 使用第三方包 实例: 第一步:创建第三方包;; (创建项目,项目下创建第三方库) 1. 新建项目 ...
- Shell之Xargs命令
目录 Shell之Xargs命令 参考 xargs命令简介 xargs命令格式 xargs实例说明 Shell之Xargs命令
- ThinkPHP5通过composer安装Workerman安装失败问题(避坑指南)
$ composer require topthink/think-workerUsing version ^2.0 for topthink/think-worker./composer.json ...