#include "Poco/Exception.h"
#include "Poco/Data/Session.h"
#include "Poco/Data/Common.h"
#include "Poco/Data/BLOB.h"
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/SessionPool.h"
#include "Poco/Data/PooledSessionImpl.h"
#include "Poco/Data/MySQL/Connector.h"
#include "Poco/Data/MySQL/MySQLException.h"
#include "Poco/Data/SQLite/Connector.h"
#include "Poco/Data/SQLite/SQLiteException.h"
#include "Poco/Data/ODBC/Connector.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include <iostream>

#include "Poco/Data/Common.h"
#include "Poco/Data/SessionPool.h"
#include "Poco/Thread.h"

int main()
{
        try
        {
                Poco::Data::MySQL::Connector::registerConnector();
                Poco::Data::SessionPool pool("MySQL", "user=root;password=;db=calserver;compress=true;auto-reconnect=true", 1, 4, 5);

Poco::Data::Session sess(pool.get());
                if(sess.isConnected())
                {
                        int count = 0;

sess<<"SELECT COUNT(*) FROM termstate", Poco::Data::into(count), Poco::Data::now;
                        std::cout << "the sum is : " << count << "recorder" <<std::endl;

}
                else
                {
                        std::cout << "*** Connected to DB"
                                << "failed" <<std::endl;
                }

Poco::Data::MySQL::Connector::unregisterConnector();
        }
        catch (Poco::Exception &ex)
        {
                std::cerr << ex.displayText() << std::endl;
        }
        return 0;
}

Makefile文件参考另外一篇博文通用Makefile模版,需要修改的为地方为:

## Customizable Section: adapt those variables to suit your program.
##==========================================================================

# The pre-processor and compiler options.
MY_CFLAGS = -I/usr/local/include/

# The linker options.
MY_LIBS   = -L/usr/local/lib/  -lPocoDataMySQL -lPocoUtil

Poco C++ MySQl demo的更多相关文章

  1. c++ poco 使用mysql中文乱码问题

    poco 是c++ 一个比较好的库,现在正在学习使用它,碰到一些问题记录在此. poco版本:poco-1.46-all ,带有数据库的支持模块 操作系统:ubuntu 1.使用poco的MySQL模 ...

  2. Poco 编译mysql

    POCO mysql需要自己添加connecter的header和lib MySQL Client: For the MySQL connector, the MySQL client librari ...

  3. golang mysql demo

    Go操作Mysql数据库 使用Go操作MySQL等数据库,一般有两种方式:一是使用database/sql接口,直接在代码里硬编码sql语句:二是使用gorm,即对象关系映射的方式在代码里抽象的操作数 ...

  4. 进一步封装poco下的mysql操作

    为方便程序对mysql操作,我对poco的mysql进行了再次封装,主要是针对自己应用需要的部分. 开发工具:netbean 系统环境:centos7 poco版本: poco-1.9.0-all 主 ...

  5. 【MYSQL】常用命令备忘录

    source 不接路径时,查找文件的路径是执行mysql命令时的路径 接路径时,使用路径+filename [root@wordpressserver mysql]# vi demo.mysql [r ...

  6. 14.7.1.2 MySQL创建用户句法

    14.7.1.2 CREATE USER Syntax 单击此处查看原文 以下是MySQL 5.7.6及以上版本的CREATE USER句法 CREATE USER [IF NOT EXISTS] u ...

  7. POCO库中文编程参考指南(1)总览

    POCO库中文编程参考指南(1)总览 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# -> @) ...

  8. Linux Programming之MySQL

    实验环境:Ubuntu13.04 在此之前有过一段使用MySQL数据库的经历,在Windows平台下使用GUI(当时是使用HeidiSQL和Workbench来管理数据库),并且有过使用Python中 ...

  9. php 连接mysql 主机 localhost,显示 No such file or directory

    打开 php.ini文件,找到这1行 mysql.default_socket 然后将它修改为 mysql.default_socket=/path/to/mysql.sock /path/to/my ...

随机推荐

  1. HTML5和CSS3的一些新特性

    html5有哪些新特性.移除了那些元素?如何处理HTML5新标签的浏览器兼容问题?如何区分 HTML 和 HTML5? 新特性: 1. 拖拽释放(Drag and drop) 2. 语义化更好的内容标 ...

  2. C#类的继承,方法的重载和覆写

    在网易云课堂上看到唐大仕老师讲解的关于类的继承.方法的重载和覆写的一段代码,注释比较详细,在此记下以加深理解. 小总结: 1.类的继承:允许的实例化方式:Student t=new Student() ...

  3. Git在Windows环境下配置Diff以及Merge工具---DiffMerge

    参考出处:http://coding4streetcred.com/blog/post/Configure-DiffMerge-for-Your-Git-DiffTool主要转自:http://blo ...

  4. C++引用的作用和用法

    引用就是某一变量(目标)的一个别名,对引用的操作与对变量直接操作完全一样. 引用的声明方法:类型标识符&引用名=目标变量名: 例如: int q; int &ra=a; 说明: &am ...

  5. C# 3D效果饼状图的绘制

    第一步:放置图表控件 拖动工具栏的Chart控件到界面上 然后选中控件,设置Series属性,将ChartType属性改为pie 第三步:设置3D效果 选择控件,设置ChartArea属性,如下 设置 ...

  6. Tips for VNCServer config

    Tips for VNCServer After the ClearCase server reboot by Jingwei, my vncserver background process is ...

  7. RSA_SHA256数字签名

    ------------------ rsa 加密与解密 ----------------------------- 数论知识的实际应用: rsa加密 把问题归结为对数字的加密. 被加密的数字为明文. ...

  8. linux 录制并回放终端会话

    发现一个比较好玩的命令,然后这块做一下记录 以下内容复制来源于 LINUX shell 脚本攻略第二版 当你需要为别人在终端上演示某些操作或是需要准备一个命令行教程时,通常得一边手动输入命令一边演示, ...

  9. 用js编程输出100以内所有的质数和个数(提示:一个大于1的自然数,除了1和它本身外,不能被其他自然数整除的数都是质数)

    <script type="text/javascript"> for(var i = 3; i <= 100; i ++) {//控制2-100所有的数i fo ...

  10. DotNetBar中collapsibleSplitContainer的问题

    如果有两个collapsibleSplitContainer,并且将splitwidth都设置为1,则只有第一个起作用,如,窗体设计中的图是: 而执行的图是: 解决办法:在窗体load里手动将第二个c ...