NodeJs连接Oracle数据库

    xiaoxiao2024-05-21  112

    Node.js连接oracle数据库,各个平台的官方详情文档:https://github.com/oracle/node-oracledb/blob/master/INSTALL.md Win7下安装node-oracledb官方步骤:https://community.oracle.com/docs/DOC-931127

    系统环境:

    windows7 x64nodejs 4.4.7Python 2.7.10NPM 1.3.1

    操作步骤简介

    原理:npm调用下载,下载成功之后交由oracle客户端解析驱动包,解析成功之后,执行完成,目录node_modules生成oracledb模块。程序运行时调用oracle sdk执行代码编译,程序运行逻辑处理,输出页面结果。

    安装Visual Studio 2017 Community(如已安装请跳过此步骤,下载地址:https://www.visualstudio.com/downloads)下载并配置oracle客户端驱动包添加环境变量手动编译oracledb模块测试连接是否正常

    安装详情

    1、下载并安装VS2017

    打开网址 https://www.visualstudio.com/downloads 选择下载 Visual Studio 2017 Community 下载后运行程序,勾选需要的功能后点击“下一步”进行安装

    2、下载解压需要安装包(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”文件目录不同,不会相互覆盖。

    3、添加环境变量

    OCI_INC_DIR=C:\oracle\instantclient_12_1\sdk\includeOCI_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

    4、手动编译oracledb

    1. 在D盘创建一个空目录:build-oraceldb 2. 进入D:\build-oracledb目录,使用GIT下载最新版的node-oracledb,地址是:https://github.com/oracle/node-oracledb 3. 进入D:\build-oracledb\node-oracledb目录,打开命令行执行命令:node-gyp configure build 以生成build目录 4. 进入D:\build-oracledb\node-oracledb\build目录,用VS2017打开binding.sln,根据提示转换为最新项目 5. 使用VS2017手动进行编译,遇到编译失败的问题使用GOOGLE来解决 6. 编译成后将node-oracledb复制到真实项目的node_modules目录中,并改名为oracledb

    5、测试连接是否正常

    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)}); }); }); }); 相关资源:Nodejs连接Oracle视频教程
    最新回复(0)