Node.js는 서버 측 프로그래밍을 가능하게 하는 매우 인기 있는 JavaScript 런타임 환경입니다. 다른 언어에 비해 매우 빠르고 유연하며 I/O 집약적인 작업을 처리할 수 있는 능력을 갖추고 있습니다. 이 외에도 Node.js는 데이터베이스와 상호 작용할 때에도 탁월합니다. 이번 글에서는 Node.js를 이용해 오라클 데이터베이스에 접근하고 운영하는 방법을 알아봅니다.
Node.js를 사용하여 Oracle 데이터베이스에 연결하기 전에 다음이 설치되어 있는지 확인해야 합니다.
- Node.js
- Oracle Instant Client
- Node.js용 oracledb 모듈
- Oracle Instant 설치 Client
Oracle Instant Client는 Node.js에서 데이터베이스에 액세스하는 데 사용할 수 있는 Oracle 데이터베이스용 경량 클라이언트입니다. Oracle Instant Client를 설치할 때 운영 체제 및 Oracle 데이터베이스 버전과 호환되는 버전을 선택하십시오. Oracle 웹사이트에서 Oracle Instant Client를 다운로드하거나 다음 명령을 사용하여 설치할 수 있습니다.
$ sudo apt-get install libaio1 $ wget https://download.oracle.com/otn_software/linux/instantclient/1912000/oracle-instantclient19.12-basic-19.12.0.0.0-1.x86_64.rpm $ sudo alien -i oracle-instantclient19.12-basic-19.12.0.0.0-1.x86_64.rpm
- Node.js용 oracledb 모듈 설치
Node.js를 사용하여 Oracle 데이터베이스에 액세스하려면 다음을 사용해야 합니다. oracledb 모듈. oracledb 모듈을 설치하려면 콘솔에서 프로젝트 폴더로 이동하여 다음 명령을 실행합니다.
$ npm install oracledb
- Oracle 데이터베이스에 연결하는 JavaScript 파일을 생성합니다.
Oracle 데이터베이스에 연결하려면 다음 정보를 사용해야 합니다. Oracle 연결에 대해 이 정보는 일반적으로 tnsnames.ora 파일에 있습니다. tnsnames.ora 파일에는 연결하려는 Oracle 데이터베이스에 대한 연결 정보가 포함되어 있습니다. tnsnames.ora 파일의 위치를 모르는 경우 Oracle 관리자에게 문의하시기 바랍니다.
프로젝트 폴더에서 dbconfig.js라는 파일을 생성하고 다음 콘텐츠를 추가하세요.
module.exports = { user: "用户名", password: "密码", connectString: "连接字符串" }
위 코드의 문자열을 Oracle 사용자 이름, 비밀번호 및 연결 문자열 값으로 바꾸세요.
- Connecting to Oracle Database
이제 Oracle Database에 연결하고 일부 작업을 수행할 준비가 되었습니다. 이렇게 하려면 JavaScript 파일을 생성한 후 다음을 수행합니다.
const oracledb = require('oracledb'); const 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; } console.log('Connection was successful!'); connection.close( function(err) { if (err) { console.error(err.message); return; } console.log('Connection was closed!'); }); });
위 코드를 실행하면 Oracle 데이터베이스에 연결할 수 있습니다. oracledb.getConnection 메소드를 사용하여 데이터베이스에 연결합니다. 연결에 실패하면 오류 메시지가 출력되고, 그렇지 않으면 연결 성공 메시지가 출력됩니다. 그런 다음 Connection.close 메소드를 사용하여 연결을 닫습니다.
- 쿼리 실행
데이터베이스에 연결되면 쿼리, 추가, 삭제, 수정 등의 작업을 수행할 수 있습니다. 쿼리를 실행하려면 이전 단계의 JavaScript 파일에 다음 코드를 추가합니다.
const oracledb = require('oracledb'); const 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; } console.log('Connection was successful!'); connection.execute( `SELECT empno, ename FROM emp`, function(err, result) { if (err) { console.error(err.message); return; } console.log(result.rows); connection.close( function(err) { if (err) { console.error(err.message); return; } console.log('Connection was closed!'); }); }); });
위 코드에서는 Connection.execute 메서드를 사용하여 쿼리를 실행합니다. 쿼리가 실패하면 오류 메시지가 인쇄되고, 그렇지 않으면 쿼리 결과 행이 인쇄됩니다.
요약
이 글에서는 Node.js를 사용하여 Oracle 데이터베이스에 액세스하는 방법을 소개합니다. 먼저 Oracle Instant Client와 Node.js의 oracledb 모듈을 설치한 후 Oracle 데이터베이스에 연결하기 위한 JavaScript 파일을 생성한 다음 데이터베이스에 연결하여 쿼리를 실행합니다. Oracle 데이터베이스와 함께 Node.js를 사용하는 장점 중 하나는 성능입니다. Node.js는 I/O 집약적인 작업과 높은 동시성을 처리하는 데 매우 적합하므로 Oracle 데이터베이스와 함께 사용할 때도 성능이 좋습니다.
위 내용은 nodejs에서 oralce에 액세스하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

반응 말 : 1) asteeplearningcurveduetoitsvastecosystem, 2) Seochallengswithclient-siderendering, 3) PlatiperFormanceIssUseInlargeApplications, 4) ComplexStateManagementAsAppSgrow, 및 5) theneedTokeEpupWithitsHouou

ReactisChallengingforbeginnersdueToitssteePlearningCurveanDParadigMshiftTocomponent 기반 Architection.1) 시작된 문서화 forasolidFoundation.2) startWithOficialDocumentationForAsolIdfoundation.2) 이해를 이해하는 방법

thecorechallengeenderatingStableanduniquekysfordynamiclistsinconsengingconsententifiersacrossre-rendersforefficialdomupdates

JavaScriptFatigueInreactismanageablewithstrestriveStriveStriveStiMelearningandcuratedInformationSources.1) 1))

TOTESTREACTCOMPONENTSUSINSUSISTATEHOOK, useJestAndReactTestingLibraryTosimulationInteractionsandStateChangeSintheUI.1) renderTheComponentAndCheckInitialState.2) SimulateUserActionSlikeClickSorformSubMissions.3) verifyTateRecerFectsin

keysinReactareCrucialforopiTizingPerformanceByIningIneficiveliceListEpdates.1) uskeyStoIndifyAndTrackListElements.2) revingArrayIndiceSkeyStopReverFormanceSues.3) 선택 가능한 식당 LikeItesteM.idtomaintaintAteAndimProvePerform

RenderingListStoimproverCiliationeficiency를 사용하면 RECTKEYSAREUNIQUEINDIFIERSEDS (1) ISHELPREACTTRACKCHANGENLISTEMS, 2) 사용 ASSABLEANDUNICEIDERIDERSISTEMIDSISRECEMENDEND, 3) RepoySingArrayIndicesAskeyStopReventIsseswithReAdering 및 4) ENS

고유 한 KeysAreCrucialInreactforoptoropiTizing and ComponentStateIntegrity


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

Dreamweaver Mac版
시각적 웹 개발 도구

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.