Mysql++是官方发布的、一个为MySQL设计的C++语言的API。Mysql++为Mysql的C-Api的再次封装,它用STL(Standard Template Language)开发并编写,并为C++开发者提供像操作STL容器一样方便的操作数据库的一套机制。其官方API介绍:MySQL++ Reference Manual

与JDBC一样,先建立连接Connection,创建Query,执行操作获得结果。

SimpleResult Query::store()进行更新、删除、创建等操作,SimpleResult代表执行状态,查询是否成功、影响了多少行。

StoreQueryResult Query::store():最常用。StoreQueryResult继承vector<mysqlpp::Row>,Row类似于vector<string>,表示一行中各列的数据。使用可以result[1][4]或result[2]["price"]。

UseQueryResult Query::use(),大结果查询,UserQueryResult是iterator,一次只能获得一个行结果,不停地next直到结束为止。

简单示例

#include <mysql++.h>
// Connect to the sample database.
mysqlpp::Connection conn(false);
if (conn.connect(db, server, user, pass)) {
// Retrieve a subset of the sample stock table set up by resetdb
// and display it.
mysqlpp::Query query = conn.query("select item from stock");
if (mysqlpp::StoreQueryResult res = query.store()) {
cout << "We have:" << endl;
for (size_t i = ; i < res.num_rows(); ++i) {
cout << '\t' << res[i][] << endl;
}
}
else {
cerr << "Failed to get item list: " << query.error() << endl;
return ;
}
return ;
}
else {
cerr << "DB connection failed: " << conn.error() << endl;
return ;
}

最新文章

  1. Security configuration of SSH login entry - enterprise security practice
  2. Oracle数据库(2)
  3. Boost的自动链接功能
  4. OpenCMS integration with Spring MVC--reference
  5. C#如何在panl控件上添加Form窗体
  6. JS中Array数组的三大属性用法
  7. JS声明对象时属性名加引号与不加引号的问题
  8. .Net Core Web/Console 下使用Nlog
  9. Educational Codeforces Round 62
  10. [转]Cordova Android 返回键拦截(backbutton)和退出(再点击一次跳出)
  11. 将MySQL数据库转移到SqlServer2008数据库
  12. Nginx使用rewrite重新定向
  13. Django(ORM查询2)
  14. 科普贴 | 数字钱包MetaMask安装使用详解,活用MetaMask轻松驾驭以太坊
  15. js-小数计算问题
  16. 15.3.14 DP练习2
  17. Python:dict字典
  18. C语言-求最大值
  19. scp -P 非22端口拷贝
  20. 同步与异步区别,Invoke与BeginInoke的区别

热门文章

  1. 【RF库Collections测试】Remove From Dictionary
  2. Effective C++ —— 构造/析构/赋值运算(二)
  3. cstring、string、wstring、int、char*、tchar、 int、dword等相互转换代码输出测试
  4. combobox组合框
  5. linux系统查看IP地址,不显示IP地址或者只显示127.0.0.1
  6. SpringMvc 400 Bad Request解决方法
  7. c++11——改进容器性能
  8. redis 之初体验(window)
  9. 腾讯云CMQ消息队列在Linux环境下的使用
  10. Ubuntu远程登录服务器--ssh的安装和配置