⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 occipool.cpp

📁 此源代码是通过occi连接oracle 9i的简单例子
💻 CPP
字号:
/***  occipool - Demontrating the Connection Pool interface of .**  DESCRIPTION :*    This program demonstates the creating and using of connection pool in the *    database and fetching records of a table.* */#include <iostream>#include <occi.h>using namespace oracle::occi;using namespace std;class occipool {  private:  Environment *env;  Connection *con;  Statement *stmt;  public :  /**   * Constructor for the occipool test case.   */  occipool ()   {    env = Environment::createEnvironment (Environment::DEFAULT);  }// end of constructor occipool ()    /**   * Destructor for the occipool test case.   */  ~occipool ()   {    Environment::terminateEnvironment (env);  }  // end of ~occipool ()  /**   * The testing logic of the test case.   */  dvoid select ()  {    cout << "occipool - Selecting records using ConnectionPool interface" <<    endl;    const string poolUserName = "SCOTT";    const string poolPassword = "TIGER";    const string connectString = "";    const string username = "SCOTT";    const string passWord = "TIGER";    unsigned int maxConn = 5;    unsigned int minConn = 3;    unsigned int incrConn = 2;    ConnectionPool *connPool = env->createConnectionPool      (poolUserName, poolPassword, connectString, minConn, maxConn, incrConn);    try{    if (connPool)      cout << "SUCCESS - createConnectionPool" << endl;    else      cout << "FAILURE - createConnectionPool" << endl;    con = connPool->createConnection (username, passWord);    if (con)      cout << "SUCCESS - createConnection" << endl;    else      cout << "FAILURE - createConnection" << endl;    }catch(SQLException ex)    {     cout<<"Exception thrown for createConnectionPool"<<endl;     cout<<"Error number: "<<  ex.getErrorCode() << endl;     cout<<ex.getMessage() << endl;    }    cout << "retrieving the data" << endl;    stmt = con->createStatement       ("SELECT author_id, author_name FROM author_tab");    ResultSet *rset = stmt->executeQuery();    while (rset->next())    {      cout << "author_id:" << rset->getInt (1) << endl;      cout << "author_name:" << rset->getString (2) << endl;    }    stmt->closeResultSet (rset);    con->terminateStatement (stmt);    connPool->terminateConnection (con);    env->terminateConnectionPool (connPool);    cout << "occipool - done" << endl;  } // end of test (Connection *)}; // end of class occipoolint main (void){  string user = "SCOTT";  string passwd = "TIGER";  string db = "";  cout << "occipool - Exhibiting interoperability of  and OCI" << endl;  occipool *demo = new occipool ();  demo->select();  delete demo; }// end of main ()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -