標籤:
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資料庫