NodeJs连接Oracle数据库

NodeJs连接Oracle数据库

参考地址:https://www.cnblogs.com/vipstone/p/4794747.html

运行原理分析

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

把两个文件解压到“D:\oracle11”文件目录不同,不会相互覆盖。 

https://download.oracle.com/otn/nt/instantclient/11204/instantclient-basiclite-windows.x64-11.2.0.4.0.zip?AuthParam=1600763843_95b08b7ec30b8bed3f58ef6b18d3acd6

https://download.oracle.com/otn/nt/instantclient/11204/instantclient-sdk-windows.x64-11.2.0.4.0.zip?AuthParam=1600763902_98c5532c94c3f1f6d2b380acf267ff78

 

2、添加环境变量

OCI_INC_DIR=D:\oracle11\instantclient-sdk-windows.x64-11.2.0.4.0\instantclient_11_2\sdk\include

OCI_LIB_DIR=D:\oracle11\instantclient-sdk-windows.x64-11.2.0.4.0\instantclient_11_2\sdk\lib\msvc

 

注意!如果本机安装oracle服务器端,请把次环境变量如下地址:

OCI_INC_DIR = D:\app\Administrator\product\11.2.0\dbhome_1\OCI\include

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

3、npm执行安装命令

cmd->npm install oracledb


4、查询demo代码

router.get('/orc_select', function (req, res, next) {

    var oracledb = require('oracledb');
    oracledb.getConnection(
        {
            user: 'username',
            password: 'password',
            connectString: '10.44.20.10:1521/ORCL'
        },
        function (err, connection) {
            if (err) {
                console.error(err.message);
                return;
            }
            connection.execute(
                "SELECT * from dual where 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)});
                });
        });

});

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值