Nodejs新人请教链接oracle

Nodejs新人请教链接oracle

node怎么链接oracle呢?不管是windos 还是linux 都没搞成功,各种问题,请老大指点一二,目前是在linux 系统上安装,如果能在winwos 上安装更好; linux 安装报错信息如下: make:进入目录’/usr/local/lib/node_modules/oracle/build’ CXX(target) Release/obj.target/oracle_bindings/src/connection.o CXX(target) Release/obj.target/oracle_bindings/src/oracle_bindings.o CXX(target) Release/obj.target/oracle_bindings/src/executeBaton.o CXX(target) Release/obj.target/oracle_bindings/src/reader.o CXX(target) Release/obj.target/oracle_bindings/src/statement.o CXX(target) Release/obj.target/oracle_bindings/src/outParam.o SOLINK_MODULE(target) Release/obj.target/oracle_bindings.node /usr/bin/ld: cannot find -locci /usr/bin/ld: cannot find -lclntsh /usr/bin/ld: cannot find -lnnz11 collect2: error: ld returned 1 exit status make: *** [Release/obj.target/oracle_bindings.node] 错误 1 make:离开目录“/usr/local/lib/node_modules/oracle/build” gyp ERR! build error gyp ERR! stack Error: make failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:267:23) gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17) gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12) gyp ERR! System Linux 3.13.0-29-generic gyp ERR! command “nodejs” “/usr/bin/node-gyp” “rebuild” gyp ERR! cwd /usr/local/lib/node_modules/oracle gyp ERR! node -v v0.10.25 gyp ERR! node-gyp -v v0.10.10 gyp ERR! not ok npm WARN This failure might be due to the use of legacy binary “node” npm WARN For further explanations, please read /usr/share/doc/nodejs/README.Debian

npm ERR! weird error 1 npm ERR! not ok code 0 在线等啊


10 回复

Nodejs 新人请教链接Oracle

问题描述

我在尝试使用Node.js连接Oracle数据库时遇到了一些问题。无论是Windows还是Linux系统,我都没有成功连接。目前主要是在Linux系统上安装,但如果能够在Windows上也成功安装会更好。

在Linux上安装时,我遇到了以下错误信息:

make: 进入目录 ‘/usr/local/lib/node_modules/oracle/build’
CXX(target) Release/obj.target/oracle_bindings/src/connection.o
CXX(target) Release/obj.target/oracle_bindings/src/oracle_bindings.o
...
/usr/bin/ld: cannot find -locci
/usr/bin/ld: cannot find -lclntsh
/usr/bin/ld: cannot find -lnnz11
collect2: error: ld returned 1 exit status
make: *** [Release/obj.target/oracle_bindings.node] 错误 1
make: 离开目录 ‘/usr/local/lib/node_modules/oracle/build’

解决方案

连接Oracle数据库可以使用oracledb模块。以下是详细的步骤和示例代码,希望能帮助你解决问题。

1. 安装依赖

首先需要安装oracledb模块。确保你的系统已经安装了Oracle Instant Client库。

在Linux上:

sudo apt-get install libaio1
wget https://download.oracle.com/otn_software/linux/instantclient/198000/instantclient-basic-linux.x64-19.8.0.0.0dbru.zip
wget https://download.oracle.com/otn_software/linux/instantclient/198000/instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip
unzip instantclient-basic-linux.x64-19.8.0.0.0dbru.zip -d /usr/local/lib
unzip instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip -d /usr/local/lib
echo /usr/local/lib/instantclient_19_8 | sudo tee -a /etc/ld.so.conf.d/oracle-instantclient.conf
sudo ldconfig

在Windows上: 下载并解压Oracle Instant Client到一个目录(例如 C:\oracle\instantclient_19_8)。

2. 安装Node.js模块

安装oracledb模块:

npm install oracledb
3. 示例代码

以下是一个简单的示例代码,用于连接到Oracle数据库并执行查询:

const oracledb = require('oracledb');

async function run() {
    let connection;

    try {
        // 连接到数据库
        connection = await oracledb.getConnection({
            user: 'your_username',
            password: 'your_password',
            connectString: 'localhost/XE'  // 或者使用服务名
        });

        console.log("Connected to Oracle Database!");

        // 执行查询
        const result = await connection.execute(
            'SELECT * FROM your_table'
        );

        console.log(result.rows);
    } catch (err) {
        console.error(err.message);
    } finally {
        if (connection) {
            try {
                // 关闭连接
                await connection.close();
            } catch (err) {
                console.error(err.message);
            }
        }
    }
}

run();

总结

以上步骤应该可以帮助你在Linux或Windows上成功连接Oracle数据库。确保你已经正确安装了Oracle Instant Client,并且配置了环境变量。希望这些信息对你有所帮助!


node-oracle需要py2.7、C++、oracle客户端等环境支持,在windows上要先安装好环境才可以 https://github.com/joeferner/node-oracle#basic-installation

这些环境我都有了 win 上我有vs2010 vs2012 vc++组建都装了 oracle10g py2.7 都在,我换win7系统 把报错信息贴出来

这些环境我都有了 win 上我有vs2010 vs2012 vc++组建都装了 oracle10g py2.7 都在,我换win7系统 把报错信息贴出来 ; oracle@0.3.7 install C:\Users\hc\node_modules\oracle node-gyp rebuild

\Users\hc\node_modules\oracle>node “D:\Program Files\nodejs\node_modules\npm
\node-gyp-bin\…\node_modules\node-gyp\bin\node-gyp.js” rebuild 此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。 connection.cpp oracle_bindings.cpp executeBaton.cpp reader.cpp \users\hc\node_modules\oracle\src\connection.h(11): fatal error C1083: 无法打 包括 件:“occi.h”: No such file or directory [C:\Users\hc\node_modules\oracle\bui o cle_bindings.vcxproj] \users\hc\node_modules\oracle\src\connection.h(11): fatal error C1083: 无法打 包括 件:“occi.h”: No such file or directory [C:\Users\hc\node_modules\oracle\bui o cle_bindings.vcxproj] statement.cpp \users\hc\node_modules\oracle\src\connection.h(11): fatal error C1083: 无法打 包括 件:“occi.h”: No such file or directory [C:\Users\hc\node_modules\oracle\bui o cle_bindings.vcxproj] outParam.cpp \users\hc\node_modules\oracle\src\executeBaton.h(12): fatal error C1083: 无法 开 括文件:“occi.h”: No such file or directory [C:\Users\hc\node_modules\oracle ild racle_bindings.vcxproj] \users\hc\node_modules\oracle\src\connection.h(11): fatal error C1083: 无法打 包括 件:“occi.h”: No such file or directory [C:\Users\hc\node_modules\oracle\bui o cle_bindings.vcxproj] \users\hc\node_modules\oracle\src\connection.h(11): fatal error C1083: 无法打 包括 件:“occi.h”: No such file or directory [C:\Users\hc\node_modules\oracle\bui o cle_bindings.vcxproj] p ERR! build error p ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.ex failed with exit code: 1 p ERR! stack at ChildProcess.onExit (D:\Program Files\nodejs\node_modules m\node_modules\node-gyp\lib\build.js:267:23) RR! stack at ChildProcess.emit (events.js:98:17) p ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:809 ) p ERR! System Windows_NT 6.1.7600 p ERR! command "node" "D:\\Program Files\\nodejs\\node_modules\\npm\\node_mod s\\node-gyp\\bin\\node-gyp.js" "rebuild" p ERR! cwd C:\Users\hc\node_modules\oracle p ERR! node -v v0.10.29 p ERR! node-gyp -v v0.13.1 p ERR! not ok m ERR! oracle@0.3.7 install:node-gyp rebuild` m ERR! Exit status 1 m ERR! m ERR! Failed at the oracle@0.3.7 install script. m ERR! This is most likely a problem with the oracle package, m ERR! not with npm itself. m ERR! Tell the author that this fails on your system: m ERR! node-gyp rebuild m ERR! You can get their info via: m ERR! npm owner ls oracle m ERR! There is likely additional logging output above.

m ERR! System Windows_NT 6.1.7600 m ERR! command “D:\Program Files\nodejs\\node.exe” “D:\Program Files\no s\node_modules\npm\bin\npm-cli.js” “install” "oracle" m ERR! cwd C:\Users\hc m ERR! node -v v0.10.29 m ERR! npm -v 1.4.14 m ERR! code ELIFECYCLE m ERR! m ERR! Additional logging details can be found in: m ERR! C:\Users\hc\npm-debug.log m ERR! not ok code 0

来大神帮我看看呀

D:\Program Files\Microsoft Visual Studio 10.0\VC\include\xlocale(323): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc [C:\Users\hc\node _modules\oracle\build \oracle_bindings.vcxproj] D:\Program Files\Microsoft Visual Studio 10.0\VC\include\xlocale(323): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc [C:\Users\hc\node _modules\oracle\build \oracle_bindings.vcxproj] D:\Program Files\Microsoft Visual Studio 10.0\VC\include\xlocale(323): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc [C:\Users\hc\node _modules\oracle\build \oracle_bindings.vcxproj] D:\Program Files\Microsoft Visual Studio 10.0\VC\include\xlocale(323): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc [C:\Users\hc\node _modules\oracle\build \oracle_bindings.vcxproj] …\src\oracle_bindings.cpp(103): warning C4244: “=”: 从“double”转换到“uint3 2_t”,可能丢 失数据 [C:\Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\oracle_bindings.cpp(169): warning C4244: “=”: 从“double”转换到“uint3 2_t”,可能丢 失数据 [C:\Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\executeBaton.cpp(91): warning C4244: “初始化”: 从“double”转换到“int ”,可能丢失数据 [C: \Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\executeBaton.cpp(92): warning C4244: “初始化”: 从“double”转换到“int ”,可能丢失数据 [C: \Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\executeBaton.cpp(93): warning C4244: “初始化”: 从“double”转换到“int ”,可能丢失数据 [C: \Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\executeBaton.cpp(94): warning C4244: “初始化”: 从“double”转换到“int ”,可能丢失数据 [C: \Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\executeBaton.cpp(95): warning C4244: “初始化”: 从“double”转换到“int ”,可能丢失数据 [C: \Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\executeBaton.cpp(96): warning C4244: “初始化”: 从“double”转换到“int ”,可能丢失数据 [C: \Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\executeBaton.cpp(97): warning C4244: “初始化”: 从“double”转换到“int ”,可能丢失数据 [C: \Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\reader.cpp(57): warning C4244: “初始化”: 从“double”转换到“int”,可 能丢失数据 [C:\Users \hc\node_modules\oracle\build\oracle_bindings.vcxproj] C:\Users\hc.node-gyp\0.10.29\deps\v8\include\v8.h(184): warning C4506: 内联函数 “v8 ::Persistent<T> v8::Persistent<T>::New(v8::Handle<T>)”没有定义 [C:\Users\hc\nod e_mo dules\oracle\build\oracle_bindings.vcxproj] with [ T=v8::Object ] C:\Users\hc.node-gyp\0.10.29\deps\v8\include\v8.h(184): warning C4506: 内联函数 “v8 ::Persistent<T> v8::Persistent<T>::New(v8::Handle<T>)”没有定义 [C:\Users\hc\nod e_mo dules\oracle\build\oracle_bindings.vcxproj] with [ T=v8::FunctionTemplate ] C:\Users\hc.node-gyp\0.10.29\deps\v8\include\v8.h(184): warning C4506: 内联函数 “v8 ::Persistent<T> v8::Persistent<T>::New(v8::Handle<T>)”没有定义 [C:\Users\hc\nod e_mo dules\oracle\build\oracle_bindings.vcxproj] with [ T=v8::Object ] C:\Users\hc.node-gyp\0.10.29\deps\v8\include\v8.h(184): warning C4506: 内联函数 “v8 ::Persistent<T> v8::Persistent<T>::New(v8::Handle<T>)”没有定义 [C:\Users\hc\nod e_mo dules\oracle\build\oracle_bindings.vcxproj] with [ T=v8::FunctionTemplate ] C:\Users\hc.node-gyp\0.10.29\deps\v8\include\v8.h(184): warning C4506: 内联函数 “v8 ::Persistent<T> v8::Persistent<T>::New(v8::Handle<T>)”没有定义 [C:\Users\hc\nod e_mo dules\oracle\build\oracle_bindings.vcxproj] with [ T=v8::Object ] …\src\connection.cpp(182): warning C4244: “初始化”: 从“double”转换到“int” ,可能丢失数据 [C:
Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] statement.cpp …\src\connection.cpp(192): warning C4101: “ex”: 未引用的局部变量 [C:\Users\hc \node_mod ules\oracle\build\oracle_bindings.vcxproj] outParam.cpp …\src\connection.cpp(590): warning C4244: “=”: 从“double”转换到“unsigned i nt”,可能丢失 数据 [C:\Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] D:\Program Files\Microsoft Visual Studio 10.0\VC\include\xmemory(212): warning C4506: 内联函数“v8::Persistent<T> v8::Persistent<T>::New(v8::Handle<T>)”没有定 义 [C:\Us ers\hc\node_modules\oracle\build\oracle_bindings.vcxproj] with [ T=v8::Object \ ] D:\Program Files\Microsoft Visual Studio 10.0\VC\include\xmemory(212): warning C4506: 内联函数“v8::Persistent<T> v8::Persistent<T>::New(v8::Handle<T>)”没有定 义 [C:\Us ers\hc\node_modules\oracle\build\oracle_bindings.vcxproj] with [ T=v8::FunctionTemplate ] D:\Program Files\Microsoft Visual Studio 10.0\VC\include\xlocale(323): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc [C:\Users\hc\node _modules\oracle\build \oracle_bindings.vcxproj] D:\Program Files\Microsoft Visual Studio 10.0\VC\include\xlocale(323): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc [C:\Users\hc\node _modules\oracle\build \oracle_bindings.vcxproj] …\src\outParam.cpp(30): warning C4244: “=”: 从“double”转换到“int”,可能丢 失数据 [C:\Users \hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\outParam.cpp(37): warning C4244: “=”: 从“double”转换到“int”,可能丢 失数据 [C:\Users \hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\outParam.cpp(44): warning C4244: “=”: 从“double”转换到“int”,可能丢 失数据 [C:\Users \hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\outParam.cpp(52): warning C4244: “=”: 从“double”转换到“float”,可能 丢失数据 [C:\Use rs\hc\node_modules\oracle\build\oracle_bindings.vcxproj] …\src\outParam.cpp(52): warning C4244: “=”: 从“int”转换到“float”,可能丢 失数据 [C:\Users
hc\node_modules\oracle\build\oracle_bindings.vcxproj] C:\Users\hc.node-gyp\0.10.29\deps\v8\include\v8.h(184): warning C4506: 内联函数 “v8 ::Persistent<T> v8::Persistent<T>::New(v8::Handle<T>)”没有定义 [C:\Users\hc\nod e_mo dules\oracle\build\oracle_bindings.vcxproj] with [ T=v8::Object ] C:\Users\hc.node-gyp\0.10.29\deps\v8\include\v8.h(184): warning C4506: 内联函数 “v8 ::Persistent<T> v8::Persistent<T>::New(v8::Handle<T>)”没有定义 [C:\Users\hc\nod e_mo dules\oracle\build\oracle_bindings.vcxproj] with [ T=v8::FunctionTemplate ] C:\Users\hc.node-gyp\0.10.29\deps\v8\include\v8.h(184): warning C4506: 内联函数 “v8 ::Persistent<T> v8::Persistent<T>::New(v8::Handle<T>)”没有定义 [C:\Users\hc\nod e_mo dules\oracle\build\oracle_bindings.vcxproj] with [ T=v8::Object ] C:\Users\hc.node-gyp\0.10.29\deps\v8\include\v8.h(184): warning C4506: 内联函数 “v8 ::Persistent<T> v8::Persistent<T>::New(v8::Handle<T>)”没有定义 [C:\Users\hc\nod e_mo dules\oracle\build\oracle_bindings.vcxproj] with [ T=v8::FunctionTemplate ] LINK : fatal error LNK1181: 无法打开输入文件“C:\instantclient_11_2\sdk\lib\msvc \vc9\ora occi10.lib” [C:\Users\hc\node_modules\oracle\build\oracle_bindings.vcxproj] gyp ERR! build error gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe failed with exit code: 1 gyp ERR! stack at ChildProcess.onExit (D:\Program Files\nodejs\node_modules
npm\node_modules\node-gyp\lib\build.js:267:23) gyp ERR! stack at ChildProcess.emit (events.js:98:17) gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:809:

gyp ERR! System Windows_NT 6.1.7600 gyp ERR! command “node” “D:\Program Files\nodejs\node_modules\npm\node_modu les\node-gyp\bin\node-gyp.js” "rebuild" gyp ERR! cwd C:\Users\hc\node_modules\oracle gyp ERR! node -v v0.10.29 gyp ERR! node-gyp -v v0.13.1 gyp ERR! not ok npm ERR! oracle@0.3.7 install: node-gyp rebuild npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the oracle@0.3.7 install script. npm ERR! This is most likely a problem with the oracle package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node-gyp rebuild npm ERR! You can get their info via: npm ERR! npm owner ls oracle npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7600 npm ERR! command “D:\Program Files\nodejs\\node.exe” “D:\Program Files\nod ejs\node_modules\npm\bin\npm-cli.js” “install” "oracle" npm ERR! cwd C:\Users\hc npm ERR! node -v v0.10.29 npm ERR! npm -v 1.4.14 npm ERR! code ELIFECYCLE npm ERR! npm ERR! Additional logging details can be found in: npm ERR! C:\Users\hc\npm-debug.log npm ERR! not ok code 0

windows 没成功坑太多 你可以参考http://my.oschina.net/zenglingfan/blog/164390 linux 下还算顺利 你是不是少个Oracle instant client没装

请教一下,我也碰到这个问题了。如何解决啊???

我的情况如下: window 7 visual studio 2010 ,oracle client 10 编译成功,npm install oracle成功 ,但访问数据出错,有大神说个法么:

错误不详细,看不出什么: the specifield module could not be found 用node-gyp编译成功,直接用visual studio编译也成功,还需要什么模块?

在Node.js中连接Oracle数据库通常需要使用oracledb模块。从你提供的错误信息来看,问题可能出在编译时缺少必要的Oracle客户端库(如occiclntshnnz11)。

以下是一些解决方案和步骤,帮助你在Linux和Windows上正确安装并连接到Oracle数据库:

1. 安装Oracle Instant Client

在Linux上:

首先,确保已经下载了适合你系统的Oracle Instant Client包,并解压到一个目录(例如/opt/instantclient_19_8)。

# 设置环境变量
export LD_LIBRARY_PATH=/opt/instantclient_19_8:$LD_LIBRARY_PATH

然后尝试重新安装oracledb模块:

npm install oracledb

在Windows上:

同样,下载适用于Windows的Instant Client,并设置环境变量指向该路径。

2. 安装oracledb模块

一旦你正确设置了Oracle Instant Client库的位置,可以尝试安装oracledb模块:

npm install oracledb

示例代码

安装完成后,你可以使用以下示例代码来连接到Oracle数据库:

const oracledb = require('oracledb');

async function run() {
    let connection;

    try {
        // 使用连接字符串或TNS名称连接
        connection = await oracledb.getConnection({
            user: 'your_username',
            password: 'your_password',
            connectString: 'your_connection_string'
        });

        const result = await connection.execute(
            `SELECT * FROM your_table`
        );
        console.log(result.rows);
    } catch (err) {
        console.error(err);
    } finally {
        if (connection) {
            try {
                await connection.close();
            } catch (err) {
                console.error(err);
            }
        }
    }
}

run();

请将your_usernameyour_passwordyour_connection_string替换为你的实际数据库凭据和连接字符串。

希望这能解决你的问题!

回到顶部