利用oracle官網提供的occi庫在windows下操作oracle資料庫__Python

來源:互聯網
上載者:User

1、先前用occi操作oracle資料庫都是失敗,後來發現是我下載的庫版本和對應的dll版本不一致導致:如32庫, 卻下載了64位的dll,因此導致在初始化環境就失敗,百思不得其解。

2、在下載好對應的32位庫和32位dll,可以正常初始化環境,操作oracle資料庫。

3、只需下載2個檔案,其他版本的檔案根據自己需要下載。如我下載的是:instantclient-basic-nt-11.2.0.3.0.zip 和 instantclient-sdk-nt-11.2.0.4.0.zip

4、我下載的檔案只支援vs2005和vs2008

5、發現運行正常,無需在安裝或配置oracle資料庫驅動等。

6、運行時依賴的庫有:針對我這次運行例子:oci.dll、oraocci11.dll、oraociei11.dll

7、dll可以在instantclient-basic-nt-11.2.0.3.0.zip 找到,

8、程式依賴的標頭檔、庫檔案可以在instantclient-sdk-nt-11.2.0.4.0.zip找到

9、依賴的標頭檔位於instantclient-sdk-nt-11.2.0.4.0.zip檔案夾中的include檔案夾

10、依賴的庫檔案位於instantclient-sdk-nt-11.2.0.4.0.zip檔案夾中的msvc檔案夾,只用2個庫檔案:oci.lib 和 oraocci11.lib

附上測試代碼:


#include <iostream>#define WIN32COMMON //避免函數重定義錯誤#include <occi.h>using namespace std;using namespace oracle::occi;int main(){//建立OCCI上下文環境Environment *env = Environment::createEnvironment();if (NULL == env) {              printf("createEnvironment error.\n");              return -1;          }elsecout << "success" << endl;string name = "使用者名稱";string pass = "密碼";string srvName = "資料庫地址/資料庫名";//資料庫地址與資料庫名之間用“/”分隔try{//建立資料庫連接Connection *conn = env->createConnection(name, pass, srvName);//使用者名稱,密碼,資料庫名 if(NULL == conn) {                   printf("createConnection error.\n");                   return -1;                  }else{    
 
                cout << "conn success" << endl;
 
               }           //關閉串連  env->terminateConnection(conn);          }catch (SQLException e)       {cout << e.what() << endl;system("pause");return -1;}       // 釋放OCCI上下文環境  Environment::terminateEnvironment(env);cout << "end!" << endl;system("pause");return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.