#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. 封装pyMysql

    #!/usr/bin/python import MySQLdb class SpiderPDO: def __init__(self): db_host = '127.0.0.1' db_user ...

  2. my understanding of (lower bound,upper bound) binary search, in C++, thanks to two post 分类: leetcode 2015-08-01 14:35 113人阅读 评论(0) 收藏

    If you understand the comments below, never will you make mistakes with binary search! thanks to A s ...

  3. 菜单导航/URHere/面包屑,通过CSS中的content简洁表达代码

    比如我们要写一个菜单导航/URHere/面包屑,如: 首页 > 个人中心 > 修改密码 代码: <ul> <li><a href="javascri ...

  4. ueditor工具栏更改按钮的默认操作

    ueditor 上的 image 按钮,默认有一个图片选择工具. 但是我想把他去掉,用上自己写的图片选择功能. 原来使用cleditor 是可以给按钮自定义一个函数.但是在ueditor就没有找到可以 ...

  5. spring注解 @Transactional

    一.@Transactional所需要的jar包 1.aopalliance.jar  这个包是AOP联盟的API包,里面包含了针对面向切面的接口.(通常Spring等其它具备动态织入功能的框架依赖此 ...

  6. css2----兼容----ie67的3像素bug

    发生条件:当浮动元素和非浮动元素相邻 时候,ie67下,两个元素就会多出3像素的间隔,其实是浮动元素产生的margin值 解决办法:1:让没有浮动的元素也浮动: 2:让浮动元素产生margin-*:- ...

  7. oracle 11g dmp文件导入10g

    需要导表的时候死活进不去, 现在没需求了.试了一把,一点问题都没.无语.下次遇到问题解决下吧. 导入导出命令:imp abc/abc123@ORCL file='d:\脚本\new\t_adverti ...

  8. ajax 中boolean值技巧

    // 利用判断 数据重复 function checkId () { var flag = true; $.ajax({ url: "", type: "post&quo ...

  9. 遗传算法的C语言实现(二)-----以求解TSP问题为例

    上一次我们使用遗传算法求解了一个较为复杂的多元非线性函数的极值问题,也基本了解了遗传算法的实现基本步骤.这一次,我再以经典的TSP问题为例,更加深入地说明遗传算法中选择.交叉.变异等核心步骤的实现.而 ...

  10. jenkins配置

    自动化测试机器172,27.14.22   IP 一.jenkins要先登录——>点击JCF_Automation——>点击左边配置 二.环境变量赋值就不会把进程杀掉