使用 Node.js 整合 SAP HANA 系统


使用 Node.js 可以将数据插入 HANA 数据库。您还可以通过 JDBC 驱动程序连接到 SAP HANA 数据库。

要通过 JDBC 进行连接,您需要安装 JDBC 驱动程序 ngdbc.jar。此驱动程序会在安装 SAP HANA 客户端时进行安装。Ngdbc.jar 文件位于此位置:-

C:\Program Files\sap\hdbclient\ on Windows platforms
/usr/sap/hdbclient/ on Linux and UNIX platforms

接下来,将 ngdb.jar 添加到类路径中并编写一个 Java 程序以连接到数据库并执行 SQL 命令。

jdbc:sap://myServer:30015/?autocommit=false

您还可以通过添加额外的主机来添加一个或多个故障转移服务器。

示例

下面是一个连接 SAP HANA 服务器的示例:-

import java.sql.*;
public class jdemo {
   public static void main(String[] argv) {
      Connection connection = null;
      try {                
         connection = DriverManager.getConnection(
            "jdbc:sap://myhdb:30015/?autocommit=false",uname,mypwrd);                
      } catch (SQLException e) {
         System.err.println("Connection Failed. User/Passwd Error?");
         return;
      }
      if (connection != null) {
         try {
            System.out.println("Connection to HANA successful!");
            Statement stmt = connection.createStatement();
            ResultSet resultSet = stmt.executeQuery("Select 'hello world' from dummy");
            resultSet.next();
            String hello = resultSet.getString(1);
            System.out.println(hello);
         } catch (SQLException e) {
            System.err.println("Query failed!");
         }
     }
   }
}

更新于:2020-03-12

321 人次浏览

开启你的职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.