標籤:
使用node 串連oracle對於剛開始入手 node項目或之前使用mysql 的同學,需要花一點時間對環境進行安裝。
鏡像
npm: https://www.npmjs.com/package/oracle
taobao: https://npm.taobao.org/package/oracle
注意:在taobao 鏡像上面有一句醒目的描述 “This library is not maintained. Oracle has made there own driver.” ,所以我這裡用的是 npm的鏡像。
安裝oralce 之前需要配置一些環境,上面兩個鏡像有描述,具體的可以參考:https://github.com/xianglongxiang/node-oracledb,下面是我安裝的一個步驟:
一、安裝工具
1、安裝Python 2.7 : https://www.python.org/download/releases/2.7/
安裝成功:
2、安裝GCC、Visual Studio 或者 similar,我這裡安裝的是Visual Studio:
Visual Studio: https://www.visualstudio.com/
安裝成功:
3.安裝oracle 的個用戶端和SDK
用戶端和SDK:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
如果你沒有帳號,可以在這裡下載
用戶端:http://pan.baidu.com/s/1nuOg9QT
SDK:http://pan.baidu.com/s/1eRERzBs
將instantclient_basic-windows.x64-12.1.0.2.0.zip 和 instantclient_sdk-windows.x64-12.1.0.2.0.zip 解壓到“同一個目錄檔案夾下”,特別注意,同一個目錄檔案夾下面。
將檔案夾地址配置到環境變數: C:\oracle\instantclient.
如果上面的工具安裝,沒有問題進行下面一步操作
二、安裝node,這裡不詳解,具體的看node 官網, https://nodejs.org/en/
三、通過Visual Studio 配置
開啟Visual Studio ->工具->NuGet包管理器->程式包管理主控台 輸入下面命令
set OCI_LIB_DIR=C:\oracle\instantclient\sdk\lib\msvc
set OCI_INC_DIR=C:\oracle\instantclient\sdk\include
四、安裝npm 安裝oracle 驅動
使用cmd或編輯器的控制台 npm install oralcedb --save
如果這裡能安裝成功,說明orace驅動已經完成好了。
五、測試是否串連成功
var oracledb = require(‘oracledb‘);
oracledb.getConnection({
connectString : "172.16.1.219/orcl",
user : "test",
password : "test"
},function(err, connection) {
if (err) console.error(err.message);
console.log("串連成功")
});
node 串連oracle