NodeJs串連Oracle資料庫

來源:互聯網
上載者:User

標籤:

nodejs串連oracle資料庫,各個平台的官方詳情文檔:https://github.com/oracle/node-oracledb/blob/master/INSTALL.md

我的nodejs串連Oracle的配置,運行環境:

windows7 x64

nodejs 0.12.7

Python 2.7.10

npm 2.11.3

運行原理分析

npm調用下載,下載成功之後交由oracle用戶端解析驅動包,解析成功之後,執行完成,目錄node_modules產生oracledb模組;

程式運行時調用oracle sdk執行代碼編譯,程式運行邏輯處理,輸出頁面結果。

實現步驟簡介

1、下載解壓需要安裝包(2個)

2、添加環境變數

3、npm執行安裝命令

4、查詢demo代碼

5、常見錯誤解決方案

 

安裝詳情

1、下載解壓需要安裝包(2個)

下載頁面:http://www.oracle.com/technetwork/topics/winx64soft-089540.html

下載名稱:

instantclient-basiclite-windows.x64-12.1.0.2.0.zip

instantclient-sdk-windows.x64-12.1.0.2.0.zip

把兩個檔案解壓到“C:\oracle\instantclient_12_1”檔案目錄不同,不會相互覆蓋。 

2、添加環境變數

OCI_INC_DIR=C:\oracle\instantclient_12_1\sdk\include

OCI_LIB_DIR=C:\oracle\instantclient_12_1\sdk\lib\msvc

 

注意!如果本機安裝oracle伺服器端,請把次環境變數如下地址:

OCI_INC_DIR = C:\app\Administrator\product\11.2.0\dbhome_1\oci\include

OCI_LIB_DIR = C:\app\Administrator\product\11.2.0\dbhome_1\OCI\lib\MSVC

3、npm執行安裝命令
npm install oracledb
4、查詢demo代碼
router.get(‘/‘, function (req, res, next) {    var oracledb = require(‘oracledb‘);    oracledb.getConnection(        {            user: ‘username‘,            password: ‘password‘,            connectString: ‘192.168.20.10:1521/ORCL‘        },        function (err, connection) {            if (err) {                console.error(err.message);                return;            }            connection.execute(                "SELECT * from CMS_FIlE where content_id=:id",                [1072],  // bind value for :id                function (err, result) {                    if (err) {                        console.error(err.message);                        return;                    }                    res.render(‘index‘, {title: ‘查詢資訊:‘ + JSON.stringify(result.rows)});                });        });});

執行後,展現效果,

5、常見錯誤解決方案

錯誤資訊,如下:

The specified procedure could not be found. 

c:\xxx\oracledb.node

解放方案:伺服器安裝版本與環境變數的OCI_INC_DIR、OCI_LIB_DIR版本不符,設定版本為一致的即可,參照上面步驟2,配置完成之後,刪除之前下載的oracledb模組,重新下載oracledb模組(npm install oracledb)即可。

 

NodeJs串連Oracle資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.