• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PocoC++MySQldemo

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

#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

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#基础笔记(第十一天)发布时间:2022-07-13
下一篇:
NAS-Initiated模式L2TP隧道配置(H3C)发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap