node js oracledb 연결

node js oracledb 연결

작성일 2023.04.22댓글 1건
    게시물 수정 , 삭제는 로그인 필요


이 코드에서 
C:\testBBS\BBS\routes\bbs.js:21 connection.execute(sql, function (err, rows) { ^ TypeError: Cannot read properties of undefined (reading 'execute') at C:\testBBS\BBS\routes\bbs.js:21:20

라는 오류가 발생합니다ㅜㅜ oracledb도 잘 설치되었고 선언도 잘 된거같은데 왜 이러는걸까요...


#node js 설치 #node js #node js express #node js download #node js 실행 #node js 란 #node js 버전 확인 #node js 업데이트 #node js 웹서버 구축 #node js 삭제

profile_image 익명 작성일 -

사용법이 잘못됐네요. 커넥션을 얻는 매소드는 getConnection()이 맞는데 getConnection뒤에 들어가는 콜백함수는 전달해도 의미가 없어요. 따라서 콜백함수의 인자중에 하나인 connection이 undefined로 판정되어 execute를 실행할 때 오류가 발생한 것이구요.

코드는 다음과 같이 수정하면 됩니다. (이후 코드 형태를 모르겠어서 보이는 대로 작성하였습니다)

let connection; let result; try{ connection = await oracledb.getConnection(dbconfig); var sql = "SELECT NO, TITLE, WRITER, DEGDATE FROM BBS"; result = await connection.execute(sql); } catch (err) { console.error("err : " + err); } finally{ if (connection) { try { await connection.close(); } catch (err) { console.error(err); } } res.render('bbs/list', result);

node js oracledb 연결

... error(err); } } res.render('bbs/list', result); 출처: https://node-oracledb.readthedocs.io/en/latest/user_guide/introduction.html#example-a-sql-select-statement-in-node-js