nodejs connect oracle on ubuntu

## prepare oracle client

(base) root@rasa-virtual-machine:~/node# wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basic-linuxx64.zip --2021-12-06 15:48:54-- https://download.oracle.com/otn_software/linux/instantclient/instantclient-basic-linuxx64.zip download.oracle.com (download.oracle.com)을(를) 해석하는 중... 23.53.224.11 접속 download.oracle.com (download.oracle.com)|23.53.224.11|:443... 접속됨. HTTP 요청을 전송했습니다. 응답을 기다리는 중입니다... 200 OK 길이: 79386308 (76M) [application/zip] 다음 위치에 저장: `instantclient-basic-linuxx64.zip' instantclient-basic-linuxx64.z 100%[====================================================>] 75.71M 96.4MB/s / 0.8s 2021-12-06 15:48:55 (96.4 MB/s) - `instantclient-basic-linuxx64.zip' 저장됨 [79386308/79386308]

 ## prepare oracle client 2

(base) root@rasa-virtual-machine:~/node# cd /opt/ (base) root@rasa-virtual-machine:/opt# mkdir oracle (base) root@rasa-virtual-machine:/opt# cd oracle/

## unzip oracle client

(base) root@rasa-virtual-machine:/opt/oracle# unzip instantclient-basic-linuxx64.zip Archive: instantclient-basic-linuxx64.zip inflating: instantclient_21_4/adrci inflating: instantclient_21_4/BASIC_LICENSE inflating: instantclient_21_4/BASIC_README inflating: instantclient_21_4/genezi linking: instantclient_21_4/libclntshcore.so -> libclntshcore.so.21.1 linking: instantclient_21_4/libclntshcore.so.12.1 -> libclntshcore.so.21.1 linking: instantclient_21_4/libclntshcore.so.18.1 -> libclntshcore.so.21.1 linking: instantclient_21_4/libclntshcore.so.19.1 -> libclntshcore.so.21.1 linking: instantclient_21_4/libclntshcore.so.20.1 -> libclntshcore.so.21.1 inflating: instantclient_21_4/libclntshcore.so.21.1 linking: instantclient_21_4/libclntsh.so -> libclntsh.so.21.1 linking: instantclient_21_4/libclntsh.so.10.1 -> libclntsh.so.21.1 linking: instantclient_21_4/libclntsh.so.11.1 -> libclntsh.so.21.1 linking: instantclient_21_4/libclntsh.so.12.1 -> libclntsh.so.21.1 linking: instantclient_21_4/libclntsh.so.18.1 -> libclntsh.so.21.1 linking: instantclient_21_4/libclntsh.so.19.1 -> libclntsh.so.21.1 linking: instantclient_21_4/libclntsh.so.20.1 -> libclntsh.so.21.1 inflating: instantclient_21_4/libclntsh.so.21.1 inflating: instantclient_21_4/libnnz21.so linking: instantclient_21_4/libocci.so -> libocci.so.21.1 linking: instantclient_21_4/libocci.so.10.1 -> libocci.so.21.1 linking: instantclient_21_4/libocci.so.11.1 -> libocci.so.21.1 linking: instantclient_21_4/libocci.so.12.1 -> libocci.so.21.1 linking: instantclient_21_4/libocci.so.18.1 -> libocci.so.21.1 linking: instantclient_21_4/libocci.so.19.1 -> libocci.so.21.1 linking: instantclient_21_4/libocci.so.20.1 -> libocci.so.21.1 inflating: instantclient_21_4/libocci.so.21.1 inflating: instantclient_21_4/libociei.so inflating: instantclient_21_4/libocijdbc21.so inflating: instantclient_21_4/liboramysql.so creating: instantclient_21_4/network/ inflating: instantclient_21_4/ojdbc8.jar inflating: instantclient_21_4/ucp.jar inflating: instantclient_21_4/uidrvci inflating: instantclient_21_4/xstreams.jar creating: instantclient_21_4/network/admin/ inflating: instantclient_21_4/network/admin/README finishing deferred symbolic links: instantclient_21_4/libclntshcore.so -> libclntshcore.so.21.1 instantclient_21_4/libclntshcore.so.12.1 -> libclntshcore.so.21.1 instantclient_21_4/libclntshcore.so.18.1 -> libclntshcore.so.21.1 instantclient_21_4/libclntshcore.so.19.1 -> libclntshcore.so.21.1 instantclient_21_4/libclntshcore.so.20.1 -> libclntshcore.so.21.1 instantclient_21_4/libclntsh.so -> libclntsh.so.21.1 instantclient_21_4/libclntsh.so.10.1 -> libclntsh.so.21.1 instantclient_21_4/libclntsh.so.11.1 -> libclntsh.so.21.1 instantclient_21_4/libclntsh.so.12.1 -> libclntsh.so.21.1 instantclient_21_4/libclntsh.so.18.1 -> libclntsh.so.21.1 instantclient_21_4/libclntsh.so.19.1 -> libclntsh.so.21.1 instantclient_21_4/libclntsh.so.20.1 -> libclntsh.so.21.1 instantclient_21_4/libocci.so -> libocci.so.21.1 instantclient_21_4/libocci.so.10.1 -> libocci.so.21.1 instantclient_21_4/libocci.so.11.1 -> libocci.so.21.1 instantclient_21_4/libocci.so.12.1 -> libocci.so.21.1 instantclient_21_4/libocci.so.18.1 -> libocci.so.21.1 instantclient_21_4/libocci.so.19.1 -> libocci.so.21.1 instantclient_21_4/libocci.so.20.1 -> libocci.so.21.1

## unzip oracle client

(base) root@rasa-virtual-machine:/opt/oracle# export LD_LIBRARY_PATH=/opt/oracle/instantclient_21_4:$LD_LIBRARY_PATH (base) root@rasa-virtual-machine:/opt/oracle# sudo ldconfig

## install libaio 

(base) root@rasa-virtual-machine:/opt/oracle# apt-get install libaio1 패키지 목록을 읽는 중입니다... 완료 의존성 트리를 만드는 중입니다 상태 정보를 읽는 중입니다... 완료 다음 새 패키지를 설치할 것입니다: libaio1 0개 업그레이드, 1개 새로 설치, 0개 제거 및 327개 업그레이드 안 함. 7,184 바이트 아카이브를 받아야 합니다. 이 작업 후 35.8 k바이트의 디스크 공간을 더 사용하게 됩니다. 받기:1 http://kr.archive.ubuntu.com/ubuntu focal/main amd64 libaio1 amd64 0.3.112-5 [7,184 B] 내려받기 7,184 바이트, 소요시간 1초 (11.3 k바이트/초) Selecting previously unselected package libaio1:amd64. (데이터베이스 읽는중 ...현재 205930개의 파일과 디렉터리가 설치되어 있습니다.) Preparing to unpack .../libaio1_0.3.112-5_amd64.deb ... Unpacking libaio1:amd64 (0.3.112-5) ... libaio1:amd64 (0.3.112-5) 설정하는 중입니다 ... Processing triggers for libc-bin (2.31-0ubuntu9) ... (base) root@rasa-virtual-machine:/opt/oracle#

## test nodejs 

var express = require('express'); var app = express(); app.use(express.static(__dirname + '/public')); app.use(express.json()); const port = process.env.PORT || 3000; var logger = require('./logger'); const dbConfig = require('./dbconfig.js'); const oracledb = require('oracledb'); try { oracledb.initOracleClient({configDir: '/opt/oracle/instantclient_21_4'}); } catch (err) { console.error('Whoops!'); console.error(err); process.exit(1); } async function run() { let connection; try { connection = await oracledb.getConnection(dbConfig); const result = await connection.execute( `select * from dual`); console.log(result.metaData); console.log(result.rows); } catch (err) { console.error(err); } finally { if (connection) { try { // Connections should always be released when not needed await connection.close(); } catch (err) { console.error(err); } } } } run();









댓글

이 블로그의 인기 게시물

[!] CDN: trunk URL couldn't be downloaded: https://cdn.cocoapods.org/CocoaPods-version.yml Response: URL using bad/illegal format or missing URL

starcraft map

Data Analysis with Superset - boardless chart