Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Introduction

As part of the Big Data group,  my assignment was to learn and document HANA learnings, and possible extend/find some of the uses that have not quite been documented yet. My first task was to find a way to connect with HANA from a Windows machine using an ODBC/JDBC connection. It was tricky at first to find a way to connect with ODBC, but digging into HANA online resources (corporate and community web portals) helped in the end. I also got to learn a lot about HANA technology and associated tools.

HANA ODBC connection through Windows (step 1)

This part was tricky because you will not find the proper driver using the regular ODBC connection wizard on Control Panel -> Administrative Tools -> Data Sources (ODBC) . The procedure is described here: https://wiki.wdf.sap.corp/wiki/display/HanaCnt/HANA+UI+Clients+Installation#HANAUIClientsInstallatio... .

Testing the ODBC connection using HANA Command Line Interface (step 2)

It is also easy to open up a HANA CLI once you have the ODBC connection installed and you have a working installation of the HANA Client on your system. All you need to do is execute: C:\Program Files (x86)\SAP\hdbclient\hdbsql.exe from the Windows Command Line;

Microsoft Windows [Version 6.1.7601]

Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\SomeUser>cd C:\Program Files (x86)\SAP\hdbclient

C:\Program Files (x86)\SAP\hdbclient>hdbsql.exe

Welcome to the SAP HANA Database interactive terminal.

Type:  \h for help with commands

       \q to quit

hdbsql=>

Loading the ODBC Driver using Python (step 3)

You should be able to use any scripting programming language to do this part. Since we were using Python extensively in our project I did this part using Python. I used the pyodbc module which can be found here: http://code.google.com/p/pyodbc/ . So if you do:

import pyodbc

conn = pyodbc.connect('DSN=<the_name_of_the_connection_you_created_in_step_1>;UID=<user_id>;PWD=<some_password>')

cursor = conn.cursor()

this should create an ODBC connection, along with a cursor, the later of which can be used to execute SQL Scripts (HANA queries) and fetch the results, such as:

cursor.execute("SELECT * FROM <SCHEMA>.<TABLE> ORDER BY <FIELD>")

print cursor.fetchall()

Endnote

Thanks to a post by Ethan: http://scn.sap.com/community/developer-center/hana/blog/2012/09/14/hana-with-odbc-on-ubuntu-1204

6 Comments