码迷,mamicode.com
首页 > 数据库 > 详细

Poco C++ MySQl demo

时间:2014-06-29 06:39:28      阅读:970      评论:0      收藏:0      [点我收藏+]

标签:blog   http   get   文件   os   art   

#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,布布扣,bubuko.com

Poco C++ MySQl demo

标签:blog   http   get   文件   os   art   

原文地址:http://www.cnblogs.com/xiaofengwei/p/3794023.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!