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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值