oracledb_npm包的使用

oracledb_npm包的使用

1.使用需求

通過Node.js搭建服務端應用,直接操作oracle數據庫,實現數據庫的連接以及增刪改查等操作。

2.開發環境

  • Windows 10
  • Oracle服務端11g
  • Oracle客戶端instantclient-basic-windows.x64-12.1.0.2.0
  • Node.js v14.2.0-x64
  • oracledb V4.2.0
  • Visual Studio 2010 Redistributable

3.環境搭建

參考鏈接:https://oracle.github.io/node-oracledb/INSTALL.html#instwin

  • 安裝Node.js,默認安裝即可;
  • 在某一文件夾下(以Node_OracleDB爲例),使用npm init初始化項目;

npm_init.png

  • 通過命令npm install oracledb --save,安裝oracledb包;
  • 下載並配置免安裝版的oracle客戶端,**注意:**要和Node.js架構匹配,目前安裝的node.js爲64位,因此要配置64位oracl客戶端,另外注意要選擇與oracle服務端版本匹配的客戶端版本;

In summary, Oracle Client 19, 18 and 12.2 can connect to Oracle Database 11.2 or greater. Oracle Client 12.1 can connect to Oracle Database 10.2 or greater. Oracle Client 11.2 can connect to Oracle Database 9.2 or greater. The technical restrictions on creating connections may be more flexible. For example Oracle Client 12.2 can successfully connect to Oracle Database 10.2.

針對Oracle服務端11g下載的是instantclient-basic-windows.x64-12.1.0.2.0,之後配置環境變量,在path環境變量中添加客戶端文件路徑,注意放到path的最前面。

  • 根據Oracle客戶端版本選擇合適的Visual Studio Redistributables進行安裝

vsr.png

4.示例程序測試

4.1 下載示例程序

https://github.com/oracle/node-oracledb克隆整個項目,將其中的examples文件夾拷貝至環境搭建時的Node_OracleDB文件夾下

4.2 修改數據庫連接配置

examples文件夾下有dbconfig.js文件,修改其中的用戶名、密碼、連接字符串等配置

dbconfig.png

4.3 運行

執行命令node .\examples\example.js,看到控制檯輸出下面數據說明數據庫操作成功。

success.png

5.參考鏈接

  1. The latest supported Visual C++ downloads
  2. node-oracledb Github地址
  3. node-oracledb api
  4. Nodejs oracledb詳細解讀

6. 資源下載

代碼文件已上傳到: https://download.csdn.net/download/wml00000/12464941

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章