如何使用 Node.js 访问 SAP HANA Cloud 数据库里的数据
登录 SAP Business Technology Platform,找到 space 下自己创建好的 HANA Cloud 实例,右键菜单选择 Copy SQL Endpoint,将 HANA Cloud 实例的 endpoint 拷贝下来:
http://25eeba68-24ce-4b2d-aaa5-ee8d599ff4a0.hana.trial-eu10.hanacloud.ondemand.com:443
稍后我们在 Node.js 代码里,会使用到。
新建一个 Node.js 应用,安装 hana client 开发库:
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 = ; i < result.length; i++)
console.log(result[i]);
dbConnection.disconnect();
}
);
});
相关文章