如何使用 Node.js 访问 SAP HANA Cloud 数据库里的数据
登錄 SAP Business Technology Platform,找到 space 下自己創(chuàng)建好的 HANA Cloud 實例,右鍵菜單選擇 Copy SQL Endpoint,將 HANA Cloud 實例的 endpoint 拷貝下來:
25eeba68-24ce-4b2d-aaa5-ee8d599ff4a0.hana.trial-eu10.hanacloud.ondemand.com:443
稍后我們在 Node.js 代碼里,會使用到。
新建一個 Node.js 應(yīng)用,安裝 hana client 開發(fā)庫:
npm install --save @sap/hana-client
完整的源代碼:
var hana = require("@sap/hana-client");var connOptions = {serverNode: "25eeba68-24ce-4b2d-aaa5-ee8d599ff4a0.hana.trial-eu10.hanacloud.ondemand.com:443",encrypt: "true",sslValidateCertificate: "false",uid: "DBADMIN",pwd: "Sgd", };var dbConnection = hana.createConnection();dbConnection.connect(connOptions, function (err) {if (err) throw err;dbConnection.exec(`SELECT TOP 1000"REGION","DESCRIPTION" FROM "PLAIN"."REGIONS"`,function (err, result) {if (err) throw err;for( var i = 0; i < result.length; i++)console.log(result[i]);dbConnection.disconnect();}); });執(zhí)行結(jié)果:
Node.js 代碼里打印的數(shù)據(jù)庫表 REGIONS,來自 PLAIN schema:
注意,使用 DBADMIN 這個用戶,只能訪問到該用戶擁有 access right 的數(shù)據(jù)庫表。
例如我們更換使用 Node.js 訪問的數(shù)據(jù)庫表名稱為 DB1.COMMUNITY:
此時,Node.js 應(yīng)用報錯:
Error: insufficient privilege: Detailed info for this error can be found with guid ‘6F6F68ED5F58804CB8C7B25D7559D0E0’
更多Jerry的原創(chuàng)文章,盡在:“汪子熙”:
總結(jié)
以上是生活随笔為你收集整理的如何使用 Node.js 访问 SAP HANA Cloud 数据库里的数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 谷歌 Pixel 7a 手机上手和拆解视
- 下一篇: 保险公司理赔打钱流程