使用 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 人次瀏覽

開啟你的職業生涯

完成課程獲得認證

開始
廣告