nodejs 오라클연동 node-oracledb 설치

1. NodeJS 설치
기준)NodeJS Version 0.12.0-x64
https://nodejs.org/en/download/ 에서 64 비트용 버전 0.12.0- 64bit
주의) 버전의 맞춤이 중요 (최신버전 4.0 기준으로 설치가 잘 안됨)

2. 오라클용 인스턴스 DLL, SDK 설치
기준) 오라클 12.1.0.2 64bit용
instantclient_basic-windows.x64-12.1.0.2.0.zip
instantclient_sdk-windows.x64-12.1.0.2.0.zip

2.1 버전에 맞는 실행가능 DLL, SDK 각 2개의 압축파일을 다운로드
다운로드 받은 파일을 같은 폴더에 압축해제
ex) C:\oracle\instantclient
2.2 압축해제 한 디렉토리에 윈도우즈 환경변수에 PATH 설정
제어판 -> 시스템 및 보안->시스템->고급시스템설정->환경변수 PATH에 추가

3. 파이선 설치
기준) Python 2.7.10 MSI 64Bit
– Download Windows x86-64 MSI installer 를 다운받아서 설치
– 설치된곳을 환경변수 PATH에 등록

4. 비주얼 스튜디오 개발 커멘드창에 환경변수 설정
기준) Visual Studion 2013
2.1 도스창에서 C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat 실행
2.2 도스창에서 각 set 설정을 실행
set OCI_LIB_DIR=C:\oracle\instantclient_12_1\sdk\lib\msvc
set OCI_INC_DIR=C:\oracle\instantclient_12_1\sdk\include

5. NodeJS 의 npm을 이용하여 node-oracledb를 설치
npm install oracledb

6. 설치테스트
node test.js

module.exports = {
  user          : process.env.NODE_ORACLEDB_USER || "db아이디",
  password      : process.env.NODE_ORACLEDB_PASSWORD || "db패스워드",
  connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || "db아이피/dbSID",
  externalAuth  : process.env.NODE_ORACLEDB_EXTERNALAUTH ? true : false
};
var oracledb = require('oracledb');
var dbConfig = require('./dbconfig.js');

oracledb.getConnection(
  {
    user          : dbConfig.user,
    password      : dbConfig.password,
    connectString : dbConfig.connectString
  },
  function(err, connection)
  {
    if (err) {
      console.error(err.message);
      return;
    }
    connection.execute(      
	"select issue_yymm, epc_code, remark, tag_location_seq,  reg_date from tag_issue WHERE rownum < :did",
      [50],
      function(err, result)
      {
        if (err) {
          console.error(err.message);
          doRelease(connection);
          return;
        }
        console.log(result.metaData);
        console.log(result.rows);
        doRelease(connection);
      });
  });

function doRelease(connection)
{
  connection.release(
    function(err) {
      if (err) {
        console.error(err.message);
      }
    });
}

참고싸이트

--NodeJS Home
https://nodejs.org

--파이선 Home
https://www.python.org/

-- 오라클 Instant Client Downloads
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

-- 오라클 NodeJs 디벨로퍼 센터
http://www.oracle.com/technetwork/database/database-technologies/node_js/oracle-node-js-2399407.html

-- 오라클 npm oracledb 홈
https://www.npmjs.com/package/oracledb

-- node-oracledb 예제
https://github.com/oracle/node-oracledb/tree/master/examples