Integrate node.js with SAP HANA system

SAP HANASAPNode.js

You can insert data into HANA database using node.js. You can also connect to SAP HANA database via JDBC driver.

To connect via JDBC, you need to install JDBC driver ngdbc.jar. This driver is installed as part of SAP HANA client installation. Ngdbc.jar file is available at this location −

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

Next is to add ngdb.jar to the classpath and write a Java program to connect to a database and execute SQL command.

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

You can also add one or more failover servers by adding additional hosts.

Example

Following is an example of connecting SAP HANA Server −

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!");
         }
     }
   }
}
raja
Published on 23-Apr-2018 18:55:27
Advertisements