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

  • 相关阅读:
    《面向模式的软件体系结构1模式系统》读书笔记(7) 通信
    《面向模式的软件体系结构2用于并发和网络化对象模式》读书笔记(5) 截取器
    Enum variable is used in switch sentencejava Anny
    How to create a dynamic range source(转) Anny
    Managing Range Names in Excel 2010(转) Anny
    Mixed Content Handling Issue on IE7/8 Anny
    How to resolve "skip non existing resourceDirectory" when using "mvn test" Anny
    Install chinese input method in Ubuntu12.04 Anny
    IDL(International Date Line) Anny
    Web Accessibility508(转) Anny
  • 原文地址:https://www.cnblogs.com/xiaofengwei/p/3794023.html
Copyright © 2011-2022 走看看