zoukankan      html  css  js  c++  java
  • Poco C++ MySQl demo

    #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

  • 相关阅读:
    python学习笔记(二十三)私有方法和私有属性
    python学习笔记(二十二)实例变量、实例方法、类变量、类方法、属性方法、静态方法
    python学习笔记(二十一)构造函数和析构函数
    python学习笔记(二十)初识面向对象
    大型网站系统架构的演化
    订单系统中并发问题和锁机制的探讨
    利用log4j+mongodb实现分布式系统中日志统一管理
    怎样编写高质量的java代码
    十五分钟学会用Hessian
    Apache Mina实战
  • 原文地址:https://www.cnblogs.com/xiaofengwei/p/3794023.html
Copyright © 2011-2022 走看看